home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / B-C / C++Source Code Fmtr Folder / Src / ParserActions.cp < prev    next >
Encoding:
Text File  |  1992-04-27  |  120.3 KB  |  3,651 lines  |  [TEXT/MPS ]

  1. #ifndef __PARSERACTIONS__
  2. #include "ParserActions.h"
  3. #endif
  4.  
  5. #ifndef __CSCANNER__
  6. #include "CScanner.h"
  7. #endif
  8.  
  9. #ifndef __FORMATTING__
  10. #include "Formatting.h"
  11. #endif
  12.  
  13. #ifndef __CDENT__
  14. #include "cdent.h"
  15. #endif
  16.  
  17. #ifndef __STRING__
  18. #include <string.h>
  19. #endif
  20.  
  21.  
  22.  
  23. #define DEBUGPARSER(proc, index)                    \
  24.     if (index >= 0 && (aParser->DebugFormatting() || aParser->DebugParser()))        \
  25.         diag(kDebug, "  # (" #proc ", %s) --> %d\n", aParser->NameOf(aToken->Type()), index);
  26.  
  27.  
  28. #define DEBUGSETCONTEXT(proc)                        \
  29.     if (aParser->DebugFormatting())                    \
  30.         diag(kDebug, "  # " #proc "\n");
  31.  
  32.  
  33. /*
  34. ** Global variables exported by ParserActions
  35. */
  36. //ƒ-
  37. PrsDeclList        gPrsDeclList;
  38. PrsId            gPrsId;
  39. PrsPlaceHolder    gLexFlush(kSLex_Flush);
  40. //ƒ+
  41.  
  42.  
  43. /*
  44. ** Parsing class instances
  45. */
  46. //ƒ-
  47. static PrsStmtList    gPrsStmtList;
  48. static PrsStmt        gPrsStmt;
  49. static PrsDecl        gPrsDecl;
  50. static PrsDo        gPrsDo;
  51. static PrsIf        gPrsIf;
  52. static PrsFor        gPrsFor;
  53. static PrsElse        gPrsElse;
  54. static PrsStruct    gPrsStruct;
  55. static PrsSwitch    gPrsSwitch;
  56. static PrsWhile        gPrsWhile;
  57. static PrsExpr        gPrsExpr;
  58. static PrsNewLine    gPrsNewLine;
  59. static PrsNewLineIf    gPrsNewLineIf;
  60. //ƒ+
  61.  
  62.  
  63. /*
  64. ** Lexical instances used as place holders on the parse stack
  65. */
  66. //ƒ-
  67. static PrsPlaceHolder    gLexParsedId(kSLex_ParsedId);
  68. static PrsPlaceHolder    gLexDecl(kSLex_Decl);
  69. static PrsPlaceHolder    gPrsDeclType(kSPrs_DeclType);
  70. static PrsPlaceHolder    gLexRBrace(kSLex_RBrace,            "]");
  71. static PrsPlaceHolder    gLexRCurly(kSLex_RCurly,            "}");
  72. static PrsPlaceHolder    gLexLParen(kSLex_LParen,            "(");
  73. static PrsPlaceHolder    gLexRParen(kSLex_RParen,            ")");
  74. static PrsPlaceHolder    gLexCase(kSLex_Case,                "case");
  75. static PrsPlaceHolder    gLexQuestion(kSLex_OpQuestion,        "?");
  76. static PrsPlaceHolder    gLexBNot(kSLex_OpBNot,                "~");
  77. static PrsPlaceHolder    gLexOpAssign(kSLex_OpAssign,        "=");
  78. static PrsPlaceHolder    gLexSemiColon(kSLex_SemiColon,        ";");
  79. static PrsPlaceHolder    gLexOperator(kSLex_ParsedId,        "operator");
  80. static PrsPlaceHolder    gLexClassColon(kSLex_ClassColon,    "::");
  81. //ƒ+
  82.  
  83.  
  84. /*
  85. ** Declare a token whose only purpose is to note that an OpenContext() has been
  86. ** done.  When this token is dropped from the stack, a CloseContext() must
  87. ** also be done
  88. */
  89. static PrsPlaceHolder gContext(kSLex_Context);
  90.  
  91.  
  92.  
  93. /*
  94. ** Context setting routines
  95. */
  96.  
  97. //µ setExprContext
  98. #pragma segment ParserActions
  99. static void setExprContext(register Formatting *aFormat)
  100. {
  101.     aFormat->SetComma(gFS_expr1);
  102.     aFormat->SetLParen(gFS_expr5);
  103.     aFormat->SetRParen(gFS_expr7);
  104.     aFormat->SetName(gFS_expr8);
  105.     aFormat->SetOperator(gFS_expr4);
  106.     aFormat->SetAssign(gFS_expr6);
  107. }
  108.  
  109.  
  110. //µ setDeclContext
  111. #pragma segment ParserActions
  112. static void setDeclContext(register Formatting *aFormat)
  113. {
  114.     aFormat->SetComma(gFS_decl1);
  115.     aFormat->SetLParen(gFS_decl3);
  116.     aFormat->SetRParen(gFS_decl11);
  117.     aFormat->SetName(gFS_expr8);
  118.     aFormat->SetOperator(gFS_expr4);
  119.     aFormat->SetAssign(gFS_expr6);
  120. }
  121.  
  122.  
  123. //µ setFundefContext
  124. #pragma segment ParserActions
  125. static void setFundefContext(register Formatting *aFormat)
  126. {
  127.     aFormat->SetComma(gFS_fundef4);
  128.     aFormat->SetSemi(gFS_decl10);
  129.     aFormat->SetLCurly(gFS_fundef11);
  130.     aFormat->SetRCurly(gFS_fundef12);
  131.     aFormat->SetLParen(gFS_fundef3);
  132.     aFormat->SetRParen(gFS_fundef6);
  133.     aFormat->SetName(gFS_fundef2);
  134.     aFormat->SetOperator(gFS_expr4);
  135.     aFormat->SetAssign(gFS_expr6);
  136. }
  137.  
  138.  
  139. //µ setFuncallContext
  140. #pragma segment ParserActions
  141. static void setFuncallContext(register Formatting *aFormat)
  142. {
  143.     aFormat->SetComma(gFS_funcall3);
  144.     aFormat->SetLParen(gFS_funcall2);
  145.     aFormat->SetRParen(gFS_funcall4);
  146. }
  147.  
  148.  
  149.  
  150. /*µ inDerivationOf
  151. ** Return true if the current item is in the derivation of a particular
  152. ** Type()
  153. */
  154. #pragma segment ParserActions
  155. static Boolean inDerivationOf(const Parser *aParser, int aType)
  156. {
  157.     int i = aParser->ItemIndex();
  158.  
  159.     while (i > 0)
  160.         if (aParser->Pick(--i)->Type() == aType)
  161.             return (true);
  162.  
  163.     return (false);
  164. }
  165.  
  166.  
  167.  
  168. /*
  169. ** Parse methods
  170. */
  171.  
  172.  
  173. /*µ kSPrs_Id    (17)
  174. **    ( 0)    ? ® • kSLex_Id                        -> ? kSLex_Id ® •
  175. **    ( 1)    ? kSLex_Id ® • "::"                    -> ? kSLex_Id "::" ® •
  176. **    ( 2)    ? kSLex_Id "::" ® • kSLex_Id        -> ? • kSLex_ParsedId
  177. **    ( 3)    ? kSLex_Id "::" ® • "~"                -> ? kSLex_Id "::" "~" ® •
  178. **    ( 4)    ? kSLex_Id "::" "~" ® • kSLex_Id    -> ? • kSLex_ParsedId
  179. **    ( 5)    ? kSLex_Id "::" "~" ® • ???            -> ? • kSLex_ParsedId ???
  180. **    ( 6)    ? kSLex_Id "::" ® • ???                -> ? • kSLex_ParsedId ???
  181. **    (15)    ? kSLex_Id ® • "::*"                -> ? • kSLex_Id "::*" ® •
  182. **    (16)    ? kSLex_Id "::*" ® • kSLex_Id        -> ? • kSLex_ParsedId
  183. **    (17)    ? KSLex_Id "::*" ® • ???            -> ? • kSLex_ParsedId "::*" ???
  184. **    ( 7)    ? kSLex_Id ® • kSLex_Id                -> ? • kSLex_ParsedId
  185. **    ( 8)    ? kSLex_Id ® • ???                    -> ? • kSLex_ParsedId ???
  186. **
  187. **    ( 9)    ? ® • "::"                            -> ? "::" ® •
  188. **    (10)    ? "::" ® • kSLex_Id                    -> ? • kSLex_ParsedId
  189. **    (11)    ? "::" ® • "~"                        -> ? "::" "~" ® •
  190. **    (12)    ? "::" "~" ® • kSLex_Id                -> ? • kSLex_ParsedId
  191. **    (13)    ? "::" "~" ® • ???                    -> ? • "::" "~" ???
  192. **    (14)    ? "::" ® • ???                        -> ? • "::" ???
  193. **
  194. **    This class holds kSLex_Ids until such time as they can be recognized
  195. ** as being either fully or partially qualified names.  Note that the only
  196. ** operator type of interest is "~".  Hence, if aToken == kSLex_Op, we use
  197. ** aToken->MinorType().  Also in the "don't care" cases, check if aToken->Type()
  198. ** is kSLex_Flush.  If so, we don't pass kSLex_Flush up the chain.
  199. */
  200. #pragma segment ParserActions
  201. Boolean
  202. PrsId::Accept(Syntactic* aToken, Parser* aParser)
  203.     {
  204.     static const short handles[] =
  205.         {
  206.         //ƒ-
  207.          4,    kSLex_Id,            4,    kSLex_Id,            kSLex_ClassColon,    kSLex_Op,    kSPrs_Id,
  208.          2,    kSLex_Id,            3,    kSLex_Id,            kSLex_ClassColon,    kSPrs_Id,
  209.          3,    kSLex_OpBNot,        3,    kSLex_Id,            kSLex_ClassColon,    kSPrs_Id,
  210.         12,    kSLex_Id,            3,    kSLex_ClassColon,    kSLex_Op,            kSPrs_Id,
  211.         16,    kSLex_Id,            3,    kSLex_Id,            kSLex_Op,            kSPrs_Id,
  212.          1,    kSLex_ClassColon,    2,    kSLex_Id,            kSPrs_Id,
  213.          7,    kSLex_Id,            2,    kSLex_Id,            kSPrs_Id,
  214.         10,    kSLex_Id,            2,    kSLex_ClassColon,    kSPrs_Id,
  215.         11,    kSLex_OpBNot,        2,    kSLex_ClassColon,    kSPrs_Id,
  216.         15,    kSLex_OpClassStar,    2,    kSLex_Id,            kSPrs_Id,
  217.          0,    kSLex_Id,            1,    kSPrs_Id,
  218.          9,    kSLex_ClassColon,    1,    kSPrs_Id,
  219.          5,    -1,                    4,    kSLex_Id,            kSLex_ClassColon,    kSLex_Op,    kSPrs_Id,
  220.          6,    -1,                    3,    kSLex_Id,            kSLex_ClassColon,    kSPrs_Id,
  221.         13,    -1,                    3,    kSLex_ClassColon,    kSLex_Op,            kSPrs_Id,
  222.         17,    -1,                    3,    kSLex_Id,            kSLex_Op,            kSPrs_Id,
  223.          8,    -1,                    2,    kSLex_Id,            kSPrs_Id,
  224.         14,    -1,                    2,    kSLex_ClassColon,    kSPrs_Id,
  225.  
  226.         -1, -1,                    0
  227.         //ƒ+
  228.         };
  229.         
  230.     // Check for kSLex_Op, use MinorType() (? == kSLex_OpBNot, kSLex_OpClassStar)
  231.     short aType = aToken->Type();
  232.     if (aType == kSLex_Op)
  233.         aType = aToken->MinorType();
  234.  
  235.     short anIndex = aParser->FindHandle(aType, handles);
  236.  
  237.     switch (anIndex)
  238.         {
  239.     case  0:    //    ? ® • kSLex_Id                        -> ? kSLex_Id ® •
  240.     case  1:    //    ? kSLex_Id ® • "::"                    -> ? kSLex_Id "::" ® •
  241.     case  3:    //    ? kSLex_Id "::" ® • "~"                -> ? kSLex_Id "::" "~" ® •
  242.     case  9:    //    ? ® • "::"                            -> ? "::" ® •
  243.     case 11:    //    ? "::" ® • "~"                        -> ? "::" "~" ® •
  244.     case 15:    //    ? kSLex_Id ® • "::*"                -> ? • kSLex_Id "::*" ® •
  245.         aParser->TopItem(aToken);
  246.         aParser->Shift(this);
  247.         break;
  248.         
  249.     case  2:    //    ? kSLex_Id "::" ® • kSLex_Id        -> ? • kSLex_ParsedId
  250.     case 16:    //    ? kSLex_Id "::*" ® • kSLex_Id        -> ? • kSLex_ParsedId
  251.         aParser->Reduce(new PrsId(aParser->Pick(2), aToken, aParser->Pick(1)), 3);
  252.         break;
  253.         
  254.     case  4:    //    ? kSLex_Id "::" "~" ® • kSLex_Id    -> ? • kSLex_ParsedId
  255.         aParser->Reduce(new PrsId(aParser->Pick(3), new PrsDestructor(aToken), aParser->Pick(2)), 4);
  256.         break;
  257.         
  258.     case  5:    //    ? kSLex_Id "::" "~" ® • ???            -> ? • kSLex_ParsedId ???
  259.         aParser->Reduce(new PrsId(aParser->Pick(3), new PrsDestructor(0), aParser->Pick(2)), 4);
  260.         if (aToken->Type() != kSLex_Flush)
  261.             return (aParser->Parse(aToken));
  262.         break;
  263.         
  264.     case  6:    //    ? kSLex_Id "::" ® • ???                -> ? • kSLex_ParsedId ???
  265.         aParser->Reduce(new PrsId(aParser->Pick(2), 0, aParser->Pick(1)), 3);
  266.         if (aToken->Type() != kSLex_Flush)
  267.             return (aParser->Parse(aToken));
  268.         break;
  269.         
  270.     case  7:    //    ? kSLex_Id ® • kSLex_Id                -> ? • kSLex_ParsedId ® kSLex_Id
  271.     case  8:    //    ? kSLex_Id ® • ???                    -> ? • kSLex_ParsedId ???
  272.         {
  273.         Syntactic* anId = aParser->Pick(1);
  274.         
  275.         anId->SexChange(kSLex_ParsedId);
  276.         aParser->Reduce(anId, 2);
  277.         if (aToken->Type() != kSLex_Flush)
  278.             return (aParser->Parse(aToken));
  279.         }
  280.         break;
  281.         
  282.     case 10:    //    ? "::" ® • kSLex_Id                    -> ? • kSLex_ParsedId
  283.         aParser->Reduce(new PrsId(0, aToken, aParser->Pick(1)), 2);
  284.         break;
  285.         
  286.     case 12:    //    ? "::" "~" ® • kSLex_Id                -> ? • kSLex_ParsedId
  287.         aParser->Reduce(new PrsId(0, new PrsDestructor(aToken), aParser->Pick(2)), 3);
  288.         break;
  289.         
  290.     case 13:    //    ? "::" "~" ® • ???                    -> ? • "::" "~" ???
  291.         {
  292.         Syntactic* aClassOp = aParser->Pick(2);
  293.         Syntactic* aBitNotOp = aParser->Pick(1);
  294.         
  295.         aParser->Reduce(aClassOp, 3);
  296.         aParser->Parse(aBitNotOp);
  297.         if (aToken->Type() != kSLex_Flush)
  298.             return (aParser->Parse(aToken));
  299.         }
  300.         break;
  301.         
  302.     case 14:    //    ? "::" ® • ???                        -> ? • "::" ???
  303.         aParser->Reduce(aParser->Pick(1), 2);
  304.         if (aToken->Type() != kSLex_Flush)
  305.             return (aParser->Parse(aToken));
  306.         break;
  307.         
  308.     case 17:    //    ? KSLex_Id "::*" ® • ???            -> ? • kSLex_ParsedId "::*" ???
  309.         {
  310.         Syntactic* anId = aParser->Pick(2);
  311.         Syntactic* aClassOp = aParser->Pick(1);
  312.         
  313.         anId->SexChange(kSLex_ParsedId);
  314.         aParser->Reduce(anId, 2);
  315.         aParser->Parse(aClassOp);
  316.         if (aToken->Type() != kSLex_Flush)
  317.             return (aParser->Parse(aToken));
  318.         }
  319.         break;
  320.         
  321.     default:
  322.         return (false);
  323.         }
  324.         
  325.     return (true);
  326.     }
  327.  
  328.  
  329.  
  330. /*µ kSPrs_StmtList    (22)
  331. **    ( 0)    ® • "("                            -> ® kSPrs_Stmt • "("
  332. **    ( 1)    ® • "["                            -> ® kSPrs_Stmt • "["
  333. **    ( 2)    ® • "break"                        -> ® kSPrs_Stmt • "break"
  334. **    ( 3)    ® • ";"                            -> ® kSPrs_Stmt • ";"
  335. **    ( 4)    ® • kSLex_Op                    -> ® kSPrs_Stmt • kSLex_Op
  336. **    ( 5)    ® • kSLex_ParsedId                -> ® kSPrs_Stmt • kSLex_ParsedId
  337. **    ( 6)    ® • "do"                        -> ® kSPrs_Stmt • "do"
  338. **    ( 7)    ® • "for"                        -> ® kSPrs_Stmt • "for"
  339. **    ( 8)    ® • "if"                        -> ® kSPrs_Stmt • "if"
  340. **    ( 9)    ® • "switch"                    -> ® kSPrs_Stmt • "switch"
  341. **    (10)    ® • "while"                        -> ® kSPrs_Stmt • "while"
  342. **    (11)    ® • "{"                            -> ® kSPrs_Stmt • "{"
  343. **    (12)    ® • kSLex_Value                    -> ® kSPrs_Stmt • kSLex_Value
  344. **    (19)    ® • kSLex_Op                    -> ® kSPrs_Stmt • kSLex_Op
  345. **        Do a normal statement
  346. **
  347. **    (21)    ® • "else"                        -> ® kSPrs_Else • "else"
  348. **    (22)    ® • kSPrs_Else                    -> ® •
  349. **        "else" statements can be commented out by #ifdef and require
  350. **        formatting.
  351. **
  352. **    (13)    ® • "struct"                    -> ® kSPrs_Decl • "struct"
  353. **    (14)    ® • kSLex_Decl                    -> ® kSPrs_Decl • kSLex_Decl
  354. **    (15)    ® kSPrs_Decl • ","                -> ® kSPrs_Decl • kSLex_Decl
  355. **        Do a declaration
  356. **
  357. **    (16)    ® • kSPrs_Stmt                    -> ® •
  358. **    (17)    ® • kSPrs_Decl                    -> ® •
  359. **        Single statments are part of the statement list
  360. **
  361. **    (18)    ® kSPrs_Stmt • "}"                -> ® • "}"
  362. **    (20)    ® kSPrs_Decl • "}"                -> ® • "}"
  363. **        Close the open statement.
  364. */
  365. #pragma segment ParserActions
  366. Boolean
  367. PrsStmtList::Accept(Syntactic* aToken, Parser* aParser)
  368.     {
  369.     Formatting* aFormat = aParser->GetFormatting();
  370.     static const short handles[] =
  371.         {
  372.         //ƒ-
  373.         15, kSLex_Comma,        2,    kSPrs_StmtList,    kSPrs_Decl,
  374.         18, kSLex_RCurly,        2,    kSPrs_StmtList,    kSPrs_Stmt,
  375.         20, kSLex_RCurly,        2,    kSPrs_StmtList,    kSPrs_Decl,
  376.          0,    kSLex_LParen,        1,    kSPrs_StmtList,
  377.          1,    kSLex_LBrace,        1,    kSPrs_StmtList,
  378.          2,    kSLex_Break,        1,    kSPrs_StmtList,
  379.          3,    kSLex_SemiColon,    1,    kSPrs_StmtList,
  380.          4,    kSLex_Op,            1,    kSPrs_StmtList,
  381.          5,    kSLex_ParsedId,        1,    kSPrs_StmtList,
  382.          6,    kSLex_Do,            1,    kSPrs_StmtList,
  383.          7,    kSLex_For,            1,    kSPrs_StmtList,
  384.          8,    kSLex_If,            1,    kSPrs_StmtList,
  385.          9,    kSLex_Switch,        1,    kSPrs_StmtList,
  386.         10,    kSLex_While,        1,    kSPrs_StmtList,
  387.         11,    kSLex_LCurly,        1,    kSPrs_StmtList,
  388.         12,    kSLex_Value,        1,    kSPrs_StmtList,
  389.         13, kSLex_Struct,        1,    kSPrs_StmtList,
  390.         14, kSLex_Decl,            1,    kSPrs_StmtList,
  391.         16, kSPrs_Stmt,            1,    kSPrs_StmtList,
  392.         17, kSPrs_Decl,            1,    kSPrs_StmtList,
  393.         19, kSLex_Op,            1,    kSPrs_StmtList,
  394.         21,    kSLex_Else,            1,    kSPrs_StmtList,
  395.         22,    kSPrs_Else,            1,    kSPrs_StmtList,
  396.  
  397.         -1, -1,                    0
  398.         //ƒ+
  399.         };
  400.  
  401.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  402.     DEBUGPARSER(StmtList, anIndex);
  403.  
  404.     switch (anIndex)
  405.         {
  406.     case  0:    //    ® • "("                            -> ® kSPrs_Stmt • "("
  407.     case  1:    //    ® • "["                            -> ® kSPrs_Stmt • "["
  408.     case  2:    //    ® • "break"                        -> ® kSPrs_Stmt • "break"
  409.     case  3:    //    ® • ";"                            -> ® kSPrs_Stmt • ";"
  410.     case  4:    //    ® • kSLex_Op                    -> ® kSPrs_Stmt • kSLex_Op
  411.     case  5:    //    ® • kSLex_ParsedId                -> ® kSPrs_Stmt • kSLex_ParsedId
  412.     case  6:    //    ® • "do"                        -> ® kSPrs_Stmt • "do"
  413.     case  7:    //    ® • "for"                        -> ® kSPrs_Stmt • "for"
  414.     case  8:    //    ® • "if"                        -> ® kSPrs_Stmt • "if"
  415.     case  9:    //    ® • "switch"                    -> ® kSPrs_Stmt • "switch"
  416.     case 10:    //    ® • "while"                        -> ® kSPrs_Stmt • "while"
  417.     case 11:    //    ® • "{"                            -> ® kSPrs_Stmt • "{"
  418.     case 12:    //    ® • kSLex_Value                    -> ® kSPrs_Stmt • kSLex_Value
  419.     case 19:    //    ® • kSLex_Op                    -> ® kSPrs_Stmt • kSLex_Op
  420.         aParser->Shift(&gPrsStmt);
  421.         return (aParser->Parse(aToken));
  422.  
  423.     case 13:    //    ® • "struct"                    -> ® kSPrs_Decl • "struct"
  424.     case 14:    //    ® • kSLex_Decl                    -> ® kSPrs_Decl • kSLex_Decl
  425.         aParser->Shift(&gPrsDecl);
  426.         return (aParser->Parse(aToken));
  427.     
  428.     case 15:    //    ® kSPrs_Decl • ","                -> ® kSPrs_Decl • kSLex_Decl
  429.         aFormat->Comma();
  430.         aFormat->Display(aToken);
  431.         return (aParser->Parse(&gLexDecl));
  432.     
  433.     case 16:    //    ® • kSPrs_Stmt                    -> ® •
  434.     case 17:    //    ® • KSPrs_Decl                    -> ® •
  435.     case 22:    //    ® • kSPrs_Else                    -> ® •
  436.         break;
  437.  
  438.     case 18:    //    ® kSPrs_Stmt • "}"                -> ® • "}"
  439.     case 20:    //    ® kSPrs_Decl • "}"                -> ® • "}"
  440.         aParser->Drop(1);
  441.         return (Accept(aToken, aParser));
  442.  
  443.     case 21:    //    ® • "else"                        -> ® kSPrs_Else • "else"
  444.         aParser->Shift(&gPrsElse);
  445.         return (aParser->Parse(aToken));
  446.  
  447.     default:
  448.         if (aToken->IsSeparator())
  449.             {
  450.             aParser->GetFormatting()->Display(aToken);
  451.             return (true);
  452.             }
  453.  
  454.         return (false);
  455.         }
  456.     
  457.     return (true);
  458.     }
  459.  
  460.  
  461.  
  462. /*µ kSPrs_DeclList    (16)
  463. **    ( 0)    ® • "struct"                    -> ® kSPrs_Decl • "struct"
  464. **    ( 1)    ® • kSLex_ParsedId                -> ® kSPrs_Decl • kSLex_ParsedId
  465. **    ( 2)    ® • kSPrs_DeclType                -> ® kSPrs_Decl • kSPrs_DeclType
  466. **    ( 3)    ® • kSLex_Decl                    -> ® kSPrs_Decl • kSLex_Decl
  467. **    (10)    ® • kSLex_Op                    -> ® kSPrs_Decl • kSLex_Op
  468. **    ( 4)    ® • ";"                            -> ® •
  469. **    ( 5)    ® • kSPrs_Decl                    -> ® •
  470. **        Almost anything is allowed to start a declaration.  However, some
  471. **        are explicitly disallowed as being impossible.
  472. **
  473. **    (11)    ® • "}"                            -> ® •
  474. **        This is a very special case.  Usually, "}" are not allowed.  However,
  475. **        if this is the only item on the parse stack, then we allow it, because
  476. **        it might be the closing "}" of an 'extern "C"' declaration that was
  477. **        buried around conditional compilation clauses.  If this is not the
  478. **        case, pass it along.
  479. **
  480. **    ( 6)    ® kSPrs_Decl • ";"                -> ® • ";"
  481. **    ( 8)    ® kSPrs_Decl • "}"                -> ® • "}"
  482. **    ( 9)    ® kSPrs_Decl • ")"                -> ® • ")"
  483. **        A declaration is terminated by a closing quote.
  484. **
  485. **    ( 7)    ® kSPrs_Decl • ","                -> ® kSPrs_Decl •
  486. **        A comma separates the components of a declaration.  Keep parsing.
  487. **
  488. **    (12)    ® • "{"                            -> ® kSPrs_Stmt • "{"
  489. **    (13)    ® • kSPrs_Stmt                    -> ® •
  490. **        More macro buffoonery.  The function header was in a #ifdef, the
  491. **        body was outside the ifdef.  Consequently, we erred.  Fix it here
  492. **        by assuming that any open curly at this position is the body of
  493. **        a function whose header was eaten.
  494. **
  495. **    (14)    ? • kSLex_Public                -> ? • kSLex_ParsedId
  496. **        Assume that the "public" keyword was not recognized because we are
  497. **        not parsing C++, we are parsing C.  Cloak the keyword and try
  498. **        again.  Do this only as a last resort (ItemIndex() == 0)
  499. **
  500. **    (15)    ? • "else"                        -> ? "else" kSPrs_Else • "else"
  501. **    (16)    ? "else" • kSPrs_Else            -> ? • 
  502. **        Assume the "else" was commented out with a #ifdef.  Parse the else,
  503. **        leaving a marker on the stack so that when the kSPrs_Else completes
  504. **        we know that it was this class that handled it.
  505. */
  506. #pragma segment ParserActions
  507. Boolean
  508. PrsDeclList::Accept(Syntactic* aToken, Parser* aParser)
  509.     {
  510.     Formatting* aFormat = aParser->GetFormatting();
  511.     static const short handles[] =
  512.         {
  513.         //ƒ-
  514.          6, kSLex_SemiColon,    2,    kSPrs_DeclList,    kSPrs_Decl,
  515.          7, kSLex_Comma,        2,    kSPrs_DeclList,    kSPrs_Decl,
  516.          8, kSLex_RCurly,        2,    kSPrs_DeclList,    kSPrs_Decl,
  517.          9, kSLex_RParen,        2,    kSPrs_DeclList,    kSPrs_Decl,
  518.          0, kSLex_Struct,        1,    kSPrs_DeclList,
  519.          1, kSLex_ParsedId,        1,    kSPrs_DeclList,
  520.          2, kSPrs_DeclType,        1,    kSPrs_DeclList,
  521.          3, kSLex_Decl,            1,    kSPrs_DeclList,
  522.          4, kSLex_SemiColon,    1,    kSPrs_DeclList,
  523.          5, kSPrs_Decl,            1,    kSPrs_DeclList,
  524.         10, kSLex_Op,            1,    kSPrs_DeclList,
  525.         11, kSLex_RCurly,        1,    kSPrs_DeclList,
  526.         12, kSLex_LCurly,        1,    kSPrs_DeclList,
  527.         13, kSPrs_Stmt,            1,    kSPrs_DeclList,
  528. //        16, kSPrs_Else,            1,    kSLex_Else,
  529.         14, kSLex_Public,        0,
  530. //        15, kSLex_Else,            0,
  531.  
  532.         -1, -1,                    0
  533.         //ƒ+
  534.         };
  535.  
  536.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  537.     DEBUGPARSER(DeclList, anIndex);
  538.  
  539.     switch (anIndex)
  540.         {
  541.     case  0:    //    ® • "struct"                    -> ® kSPrs_Decl • "struct"
  542.     case  1:    //    ® • kSLex_ParsedId                -> ® kSPrs_Decl • kSLex_ParsedId
  543.     case  2:    //    ® • kSPrs_DeclType                -> ® kSPrs_Decl • kSPrs_DeclType
  544.     case  3:    //    ® • kSLex_Decl                    -> ® kSPrs_Decl • kSLex_Decl
  545.     case 10:    //    ® • kSLex_Op                    -> ® kSPrs_Decl • kSLex_Op
  546.         aParser->Shift(&gPrsDecl);
  547.         aParser->Parse(aToken);
  548.         break;
  549.  
  550.     case  4:    //    ® • ";"                            -> ® •
  551.         aFormat->SetGlue(gFS_stmt1);
  552.         aFormat->Display(aToken);
  553.         break;
  554.  
  555.     case  5:    //    ® • kSPrs_Decl                    -> ® •
  556.     case 13:    //    ® • kSPrs_Stmt                    -> ® •
  557.         break;
  558.  
  559.     case 11:    //    ® • "}"                            -> ® •
  560.         // Only if this is the only one do we allow it
  561.         if (aParser->Depth() > 1)
  562.             return (false);
  563.         aFormat->SetGlue(gFS_decl9);
  564.         aFormat->Display(aToken);
  565.         break;
  566.  
  567.     case  6:    //    ® kSPrs_Decl • ";"                -> ® • ";"
  568.         aFormat->SetGlue(gFS_decl10);
  569.         aFormat->Display(aToken);
  570.         aParser->Drop(1);
  571.         break;
  572.  
  573.     case  7:    //    ® kSPrs_Decl • ","                -> ® kSPrs_Decl •
  574.         aFormat->Comma();
  575.         aFormat->Display(aToken);
  576.         break;
  577.  
  578.     case  8:    //    ® kSPrs_Decl • "}"                -> ® • "}"
  579.     case  9:    //    ® kSPrs_Decl • ")"                -> ® • ")"
  580.         aParser->Drop(1);
  581.         return (Accept(aToken, aParser));
  582.  
  583.     case 12:    //    ® • "{"                            -> ® kSPrs_Stmt • "{"
  584.         // Only if this is the only one we allow it
  585.         if (aParser->Depth() > 1)
  586.             return (false);
  587.         aParser->Shift(&gPrsStmt);
  588.         aParser->Parse(aToken);
  589.         break;
  590.  
  591.     case 14:    //    ® • kSLex_Public                -> • kSLex_ParsedId
  592.         if (aParser->ItemIndex() != 0)
  593.             return (false);
  594.         return (aParser->Parse(new PrsAsId(aToken)));
  595.  
  596.     case 15:    //    ? • "else"                        -> ? "else" kSPrs_Else • "else"
  597.         aParser->Shift(aToken);
  598.         aParser->Shift(&gPrsElse);
  599.         aParser->Parse(aToken);
  600.         break;
  601.  
  602.     case 16:    //    ? "else" • kSPrs_Else            -> ? • 
  603.         aParser->Drop(1);
  604.         break;
  605.  
  606.     default:
  607.         if (aToken->IsSeparator())
  608.             {
  609.             aFormat->Display(aToken);
  610.             return (true);
  611.             }
  612.         return (false);
  613.         }
  614.  
  615.     return (true);
  616.     }
  617.  
  618.  
  619.  
  620. /*µ kSPrs_Stmt    (36)
  621. **    ( 0)    ® • "{"                                    -> ® kSLex_Context kSPrs_StmtList •
  622. **    ( 1)    ® kSLex_Context kSPrs_StmtList • "}"    -> • kSPrs_Stmt
  623. **        Produce a statement list bracketed by "{" .. "}"
  624. **
  625. **    ( 2)    ® • ";"                        -> • kSPrs_Stmt
  626. **        Do the single semicolon sort of statement
  627. **
  628. **    ( 3)    ® • "do"                    -> kSPrs_Do • "do"
  629. **    ( 4)    ® • "for"                    -> kSPrs_For • "for"
  630. **    ( 5)    ® • "if"                    -> kSPrs_If • "if"
  631. **    ( 6)    ® • "switch"                -> kSPrs_Switch • "switch"
  632. **    ( 7)    ® • "while"                    -> kSPrs_While • "while"
  633. **    (36)    ® • "else"                    -> • kSPrs_Stmt "else"
  634. **        Switch on the keyword and call the proper parser
  635. **
  636. **    ( 8)    ® • kSLex_ParsedId            -> ® kSLex_ParsedId • 
  637. **    ( 9)    ® kSLex_ParsedId • ":"        -> ® • 
  638. **    (10)    ® kSLex_ParsedId • ???        -> ® kSLex_Context kSPrs_Expr • kSLex_ParsedId ???
  639. **        An identifier can be either an expression or a label.  Defer until
  640. **        the ":" or something else is seen.
  641. **
  642. **    (11)    ® • "("                        -> ® kSLex_Context kSPrs_Expr • "("
  643. **    (12)    ® • "["                        -> ® kSLex_Context kSPrs_Expr • "["
  644. **    (13)    ® • kSLex_Value                -> ® kSLex_Context kSPrs_Expr • kSLex_Value
  645. **    (14)    ® • kSLex_Op                -> ® kSLex_Context kSPrs_Expr • kSLex_Op
  646. **    (15)    ® kSLex_Context kSPrs_Expr • ";"        -> • kSPrs_Stmt
  647. **    (16)    ® kSLex_Context kSPrs_Expr • kSPrs_Decl    -> ® • kSPrs_Decl
  648. **    (17)    ® kSLex_Context kSPrs_Expr • ","        -> ® kSLex_Context kSPrs_Decl • kSLex_Decl
  649. **    (18)    ® kSLex_Context kSPrs_Expr • "}"        -> ® • "}"
  650. **    (19)    ® kSLex_Context kSPrs_Expr • ???        -> ® • ???
  651. **        Parse an expression.  The "," case could be a comma expression or it
  652. **        could be a declaration we thought was an expression.  But we're a
  653. **        formatter, so we'll assume the usual case will be a declaration we
  654. **        thought was an expression, as most statements don't contain comma
  655. **        expressions outside parentheses.
  656. **
  657. **    (20)    ® • kSLex_Break                -> ® •
  658. **    (21)    ® • kSLex_Break                -> ® kSLex_Break •
  659. **    (22)    ® kSLex_Break • ";"            -> • kSPrs_Stmt
  660. **    (23)    ® kSLex_Break • ???            -> ® kSLex_Context kSPrs_Expr • ???
  661. **        Do a break or goto/return.  The goto/return case has an optional
  662. **        expression following it.
  663. **
  664. **    (24)    ® • kSLex_Decl                        -> ® kSLex_Context kSPrs_Decl • kSLex_Decl
  665. **    (25)    ® • "struct"                        -> ® kSLex_Context kSPrs_Decl • "struct"
  666. **    (26)    ® kSLex_Context • kSPrs_Decl        -> • kSPrs_Stmt
  667. **    (27)    ® kSLex_Context kSPrs_Decl • ","    -> ® kSLex_Context kSPrs_Decl •
  668. **    (28)    ® kSLex_Context kSPrs_Decl • ???    -> ® • ???
  669. **        A declaration statement.  Do it.
  670. **
  671. **    (29)    ® • "}"                                    -> • kSPrs_Stmt "}"
  672. **    (30)    ® kSLex_Context kSPrs_Expr • "do"        -> • kSPrs_Stmt "do"
  673. **    (31)    ® kSLex_Context kSPrs_Expr • "for"        -> • kSPrs_Stmt "for"
  674. **    (32)    ® kSLex_Context kSPrs_Expr • "if"        -> • kSPrs_Stmt "if"
  675. **    (33)    ® kSLex_Context kSPrs_Expr • "switch"    -> • kSPrs_Stmt "switch"
  676. **    (34)    ® kSLex_Context kSPrs_Expr • "while"    -> • kSPrs_Stmt "while"
  677. **    (35)    ® kSLex_Context kSPrs_Expr • "}"        -> • "}"
  678. **        The statement did not terminate.  Terminate the statement and the
  679. **        pass on the terminators.  This sort of thing usually occurs from
  680. **        the use of macros which don't end in ";"
  681. **
  682. **    Formatting.
  683. **        A context is opened whenever the stack shifts into the state
  684. **        "® kSPrs_Expr" and is closed whenever the kSPrs_Expr is removed.
  685. **        A context is also opened and closed around "{…}"
  686. */
  687. #pragma segment ParserActions
  688. Boolean
  689. PrsStmt::Accept(Syntactic* aToken, Parser* aParser)
  690.     {
  691.     Formatting* aFormat = aParser->GetFormatting();
  692.     static const short handles[] =
  693.         {
  694.         //ƒ-
  695.          1, kSLex_RCurly,        3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_StmtList,
  696.         15, kSLex_SemiColon,    3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  697.         16, kSPrs_Decl,            3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  698.         17, kSLex_Comma,        3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  699.         18, kSLex_RCurly,        3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  700.         27, kSLex_Comma,        3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Decl,
  701.         30, kSLex_Do,            3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  702.         31, kSLex_For,            3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  703.         32, kSLex_If,            3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  704.         33, kSLex_Switch,        3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  705.         34, kSLex_While,        3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  706.         35, kSLex_RCurly,        3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  707.          9, kSLex_Colon,        2,    kSPrs_Stmt,    kSLex_ParsedId,
  708.         22,    kSLex_SemiColon,    2,    kSPrs_Stmt,    kSLex_Break,
  709.         26,    kSPrs_Decl,            2,    kSPrs_Stmt,    kSLex_Context,
  710.          0,    kSLex_LCurly,        1,    kSPrs_Stmt,
  711.          2,    kSLex_SemiColon,    1,    kSPrs_Stmt,
  712.          3,    kSLex_Do,            1,    kSPrs_Stmt,
  713.          4,    kSLex_For,            1,    kSPrs_Stmt,
  714.          5,    kSLex_If,            1,    kSPrs_Stmt,
  715.          6,    kSLex_Switch,        1,    kSPrs_Stmt,
  716.          7,    kSLex_While,        1,    kSPrs_Stmt,
  717.          8,    kSLex_ParsedId,        1,    kSPrs_Stmt,
  718.         11,    kSLex_LParen,        1,    kSPrs_Stmt,
  719.         12,    kSLex_LBrace,        1,    kSPrs_Stmt,
  720.         13,    kSLex_Value,        1,    kSPrs_Stmt,
  721.         14,    kSLex_Op,            1,    kSPrs_Stmt,
  722.         20,    kSLex_Break,        1,    kSPrs_Stmt,
  723. //        21,    kSLex_Break,        1,    kSPrs_Stmt,
  724.         24,    kSLex_Decl,            1,    kSPrs_Stmt,
  725.         25,    kSLex_Struct,        1,    kSPrs_Stmt,
  726.         29, kSLex_RCurly,        1,    kSPrs_Stmt,
  727.         36, kSLex_Else,            1,    kSPrs_Stmt,
  728.         19, -1,                    3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Expr,
  729.         28, -1,                    3,    kSPrs_Stmt,    kSLex_Context,    kSPrs_Decl,
  730.         10, -1,                    2,    kSPrs_Stmt,    kSLex_ParsedId,
  731.         23,    -1,                    2,    kSPrs_Stmt,    kSLex_Break,
  732.  
  733.         -1, -1,                    0
  734.         //ƒ+
  735.         };
  736.  
  737.     /*
  738.     ** Hack.  State 21 is hidden under state 20.  Discover if this is 20
  739.     */
  740.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  741.     switch (anIndex)
  742.         {
  743.     case 20:
  744.         switch (aToken->MinorType())
  745.             {
  746.         case kSLex_BreakReturn:
  747.         case kSLex_BreakGoto:
  748.             anIndex = 21;
  749.             break;
  750.             }
  751.         }
  752.  
  753.     DEBUGPARSER(Stmt, anIndex);
  754.  
  755.     switch (anIndex)
  756.         {
  757.     case  0:    //    ® • "{"                                    -> ® kSLex_Context kSPrs_StmtList •
  758.         aFormat->SetGlue(gFS_stmt0);
  759.         aFormat->OpenContext();
  760.         DEBUGSETCONTEXT(setExprContext)
  761.         setExprContext(aFormat);
  762.         aFormat->SetGlue(gFS_block1);
  763.         aFormat->Display(aToken);
  764.         aParser->Shift(&gContext);
  765.         aParser->Shift(&gPrsStmtList);
  766.         break;
  767.         
  768.     case  1:    //    ® kSLex_Context kSPrs_StmtList • "}"    -> • kSPrs_Stmt
  769.         aFormat->SetGlue(gFS_block2);
  770.         aFormat->Display(aToken);
  771.         aFormat->CloseContext();
  772.         aParser->Reduce(&gPrsStmt, 3);
  773.         break;
  774.         
  775.     case  2:    //    ® • ";"                        -> • kSPrs_Stmt
  776.         aFormat->SetGlue(gFS_stmt0);
  777.         aFormat->SetGlue(gFS_stmt1);
  778.         aFormat->Display(aToken);
  779.         aParser->Reduce(&gPrsStmt, 1);
  780.         break;
  781.         
  782.     case  3:    //    ® • "do"                    -> kSPrs_Do • "do"
  783.         aParser->TopItem(&gPrsDo);
  784.         aParser->Parse(aToken);
  785.         break;
  786.         
  787.     case  4:    //    ® • "for"                    -> kSPrs_For • "for"
  788.         aParser->TopItem(&gPrsFor);
  789.         aParser->Parse(aToken);
  790.         break;
  791.         
  792.     case  5:    //    ® • "if"                    -> kSPrs_If • "if"
  793.         aParser->TopItem(&gPrsIf);
  794.         aParser->Parse(aToken);
  795.         break;
  796.         
  797.     case  6:    //    ® • "switch"                -> kSPrs_Switch • "switch"
  798.         aParser->TopItem(&gPrsSwitch);
  799.         aParser->Parse(aToken);
  800.         break;
  801.         
  802.     case  7:    //    ® • "while"                    -> kSPrs_While • "while"
  803.         aParser->TopItem(&gPrsWhile);
  804.         aParser->Parse(aToken);
  805.         break;
  806.         
  807.     case  8:    //    ® • kSLex_ParsedId            -> ® kSLex_ParsedId • 
  808.         aParser->Shift(aToken);
  809.         break;
  810.         
  811.     case  9:    //    ® kSLex_ParsedId • ":"            -> ® • 
  812.         aFormat->SetGlue(gFS_label1);
  813.         aFormat->Display(aParser->TopItem());
  814.         aFormat->Display(aToken);
  815.         aParser->Drop(1);
  816.         break;
  817.         
  818.     case 10:    //    ® kSLex_ParsedId • ???            -> ® kSLex_Context kSPrs_Expr • kSLex_ParsedId ???
  819.         if (aToken->IsSeparator())
  820.             {
  821.             aFormat->Display(aToken);
  822.             return (true);
  823.             }
  824.         {
  825.         Syntactic* aName = aParser->TopItem();
  826.         
  827.         aFormat->SetGlue(gFS_stmt0);
  828.         aFormat->OpenContext();
  829.         DEBUGSETCONTEXT(setExprContext)
  830.         setExprContext(aFormat);
  831.         aParser->TopItem(&gContext);
  832.         aParser->Shift(&gPrsExpr);
  833.         aParser->Parse(aName);
  834.         return (aParser->Parse(aToken));
  835.         }
  836.  
  837.     case 11:    //    ® • "("                        -> ® kSLex_Context kSPrs_Expr • "("
  838.     case 12:    //    ® • "["                        -> ® kSLex_Context kSPrs_Expr • "["
  839.     case 13:    //    ® • kSLex_Value                -> ® kSLex_Context kSPrs_Expr • kSLex_Value
  840.     case 14:    //    ® • kSLex_Op                -> ® kSLex_Context kSPrs_Expr • kSLex_Op
  841.         aFormat->SetGlue(gFS_stmt0);
  842.         aFormat->OpenContext();
  843.         DEBUGSETCONTEXT(setExprContext)
  844.         setExprContext(aFormat);
  845.         aParser->Shift(&gContext);
  846.         aParser->Shift(&gPrsExpr);
  847.         aParser->Parse(aToken);
  848.         break;
  849.         
  850.     case 15:    //    ® kSLex_Context kSPrs_Expr • ";"        -> • kSPrs_Stmt
  851.         aFormat->SetGlue(gFS_stmt1);
  852.         aFormat->Display(aToken);
  853.         aFormat->CloseContext();
  854.         aParser->Reduce(&gPrsStmt, 3);
  855.         break;
  856.         
  857.     case 19:    //    ® kSLex_Context kSPrs_Expr • ???        -> ® • ???
  858.         if (aToken->IsSeparator())
  859.             {
  860.             aFormat->Display(aToken);
  861.             return (true);
  862.             }
  863.         // !!! FALL THROUGH !!!
  864.  
  865.     case 16:    //    ® kSLex_Context kSPrs_Expr • kSPrs_Decl    -> ® • kSPrs_Decl
  866.     case 18:    //    ® kSLex_Context kSPrs_Expr • "}"        -> ® • "}"
  867.         aFormat->CloseContext();
  868.         aParser->Drop(2);
  869.         return (Accept(aToken, aParser));
  870.         
  871.         
  872.     case 17:    //    ® kSLex_Context kSPrs_Expr • ","        -> ® kSLex_Context kSPrs_Decl • kSLex_Decl
  873.         aFormat->Comma();
  874.         aFormat->Display(aToken);
  875.         aFormat->RestoreIndent();
  876.         DEBUGSETCONTEXT(setDeclContext)
  877.         setDeclContext(aFormat);
  878.         aParser->TopItem(&gPrsDecl);
  879.         aParser->Parse(&gLexDecl);
  880.         break;
  881.  
  882.     case 27:    //    ® kSPrs_Decl • ","            -> ® kSPrs_Decl •
  883.         aFormat->Comma();
  884.         aFormat->Display(aToken);
  885.         break;
  886.  
  887.     case 20:    //    ® • kSLex_Break                -> ® •
  888.         aFormat->SetGlue(gFS_break1);
  889.         aFormat->Display(aToken);
  890.         break;
  891.  
  892.     case 21:    //    ® • kSLex_Break                -> ® kSLex_Break •
  893.         aParser->Shift(aToken);
  894.         break;
  895.  
  896.     case 22:    //    ® kSLex_Break • ";"            -> • kSPrs_Stmt
  897.         aFormat->SetGlue(gFS_break1);
  898.         aFormat->Display(aParser->TopItem());
  899.         aFormat->SetGlue(gFS_stmt1);
  900.         aFormat->Display(aToken);
  901.         aParser->Reduce(this, 2);
  902.         break;
  903.         
  904.     case 23:    //    ® kSLex_Break • ???            -> ® kSLex_Context kSPrs_Expr • ???
  905.         if (aToken->IsSeparator())
  906.             {
  907.             aFormat->Display(aToken);
  908.             return (true);
  909.             }
  910.         aFormat->SetGlue(aParser->TopItem()->MinorType() == kSLex_BreakGoto ? gFS_goto1 : gFS_return1);
  911.         aFormat->Display(aParser->TopItem());
  912.         aFormat->OpenContext();
  913.         DEBUGSETCONTEXT(setExprContext)
  914.         setExprContext(aFormat);
  915.         aParser->TopItem(&gContext);
  916.         aParser->Shift(&gPrsExpr);
  917.         aParser->Parse(aToken);
  918.         break;
  919.  
  920.     case 24:    //    ® • kSLex_Decl                -> ® kSLex_Context kSPrs_Decl • kSLex_Decl
  921.     case 25:    //    ® • "struct"                -> ® kSLex_Context kSPrs_Decl • "struct"
  922.         aFormat->OpenContext();
  923.         DEBUGSETCONTEXT(setDeclContext)
  924.         setDeclContext(aFormat);
  925.         aParser->Shift(&gContext);
  926.         aParser->Shift(&gPrsDecl);
  927.         aParser->Parse(aToken);
  928.         break;
  929.  
  930.     case 26:    //    ® kSLex_Context • kSPrs_Decl        -> • kSPrs_Stmt
  931.         aFormat->CloseContext();
  932.         aParser->Reduce(this, 2);
  933.         break;
  934.  
  935.     case 28:    //    ® kSLex_Context kSPrs_Decl • ???    -> ® • ???
  936.         if (aToken->IsSeparator())
  937.             {
  938.             aFormat->Display(aToken);
  939.             return (true);
  940.             }
  941.         aFormat->CloseContext();
  942.         aParser->Drop(2);
  943.         return (Accept(aToken, aParser));
  944.  
  945.     case 29:    //    ® • "}"                                    -> • kSPrs_Stmt "}"
  946.         aParser->Reduce(&gPrsStmt, 1);
  947.         return (aParser->Parse(aToken));
  948.  
  949.     case 30:    //    ® kSLex_Context kSPrs_Expr • "do"        -> • kSPrs_Stmt "do"
  950.     case 31:    //    ® kSLex_Context kSPrs_Expr • "for"        -> • kSPrs_Stmt "for"
  951.     case 32:    //    ® kSLex_Context kSPrs_Expr • "if"        -> • kSPrs_Stmt "if"
  952.     case 33:    //    ® kSLex_Context kSPrs_Expr • "switch"    -> • kSPrs_Stmt "switch"
  953.     case 34:    //    ® kSLex_Context kSPrs_Expr • "while"    -> • kSPrs_Stmt "while"
  954.         aFormat->CloseContext();
  955.         aParser->Reduce(this, 3);
  956.         return (aParser->Parse(aToken));
  957.  
  958.     case 35:    //    ® kSLex_Context kSPrs_Expr • "}"        -> • "}"
  959.         aFormat->CloseContext();
  960.         aParser->Drop(3);
  961.         return (Accept(aToken, aParser));
  962.  
  963.     case 36:    //    ® • "else"                    -> • kSPrs_Stmt "else"
  964.         aParser->Reduce(this, 1);
  965.         return (aParser->Parse(aToken));
  966.  
  967.     default:
  968.         if (aToken->IsSeparator())
  969.             {
  970.             aFormat->Display(aToken);
  971.             return (true);
  972.             }
  973.         return (false);
  974.         }
  975.         
  976.     return (true);
  977.     }
  978.     
  979.  
  980. /*µ    kSPrs_Decl    (76)
  981. **    ( 0)    ® • ";"                                -> • kSPrs_Decl
  982. **    An empty declaration, either a statement or just part of one
  983. **
  984. **    ( 1)    ® • kSPrs_Decl                        -> • kSPrs_Decl
  985. **    A parse is completed, probably by a "struct" declaration.
  986. **
  987. **    ( 2)    ® • "struct"                        -> ® kSLex_Context kSLex_Decl kSPrs_Struct • "struct"
  988. **    A structure declaration begins with the structure word.  When done, it
  989. **    yields a kSPrs_Decl (if a complete declaration) or a kSPrs_DeclType.
  990. **
  991. **    ( 3)    ® • kSLex_ParsedId                    -> ® kSLex_Context kSLex_Decl •
  992. **    ( 4)    ® • kSLex_Decl                        -> ® kSLex_Context kSLex_Decl •
  993. **    (76)    ® • kSLex_Ellipsis                    -> ® kSLex_Context kSLex_Decl •
  994. **    An identifier here is treated the same as a type word.  They both
  995. **    indicate that at least one type word has been found.
  996. **
  997. **    ( 5)    ® • kSLex_Op                        -> ® kSLex_Context kSLex_Decl •
  998. **    (52)    ® • kSLex_OpBNot                    -> ® kSLex_OpBNot •
  999. **    ( 6)    ® kSLex_OpBNot • kSLex_ParsedId        -> ® kSLex_Context kSLex_Decl kSLex_ParsedId •
  1000. **    (14)    ® kSLex_OpBNot • ???                -> ® kSLex_Context kSLex_Decl • ???
  1001. **    Recognize a destructor name.  If the item following the "~" is not something
  1002. **    we recognize, reduce and feed it directly to ourself.  If the operator is
  1003. **    not a "~", we assume we are in a declaration and try again.
  1004. **
  1005. **
  1006. **    (74)    ® • kSLex_Value                        -> ® kSLex_Context kSPrs_Expr • kSLex_Value
  1007. **    (75)    ® kSLex_Context kSPrs_Expr • ???    -> ® kSLex_Context kSLex_Decl • ???
  1008. **    Alright, so it isn't just a list of declarations.  It has a value in it.
  1009. **    Parse the expression beginning with the value.  When the expression
  1010. **    completes, get rid of it and reduce to the "® kSLex_Context kSLex_Decl"
  1011. **    state.
  1012. **
  1013. **
  1014. **        The common state for a completed declaration is
  1015. **                    ® kSLex_Context kSLex_Decl
  1016. **    indicating that at least one piece of the declaration has been parsed.
  1017. **    When in this state, a ";", "}" or ")" will yield a declaration.
  1018. **
  1019. **    ( 7)    ® kSLex_Context kSLex_Decl • ";"    -> ® • kSPrs_Decl
  1020. **    ( 8)    ® kSLex_Context kSLex_Decl • ","    -> ® • ","
  1021. **    ( 9)    ® kSLex_Context kSLex_Decl • ")"    -> ® • ")"
  1022. **    (69)    ® kSLex_Context kSLex_Decl • "}"    -> ® • "}"
  1023. **    End of a declaration.  Pass it along.
  1024. **
  1025. **
  1026. **    (10)    ® kSLex_Context kSLex_Decl • kSPrs_DeclType        -> ® kSLex_Context kSLex_Decl •
  1027. **    (11)    ® kSLex_Context kSLex_Decl • kSLex_Decl            -> ® kSLex_Context kSLex_Decl •
  1028. **    (12)    ® kSLex_Context kSLex_Decl • kSPrs_Decl            -> ® • kSPrs_Decl
  1029. **    (15)    ® kSLex_Context kSLex_Decl • "struct"            -> ® • "struct"
  1030. **    Two or more declaration words in a row collapse into one.  kSPrs_DeclType
  1031. **    is produced when a structure declaration is recognized.  kSPrs_Decl is
  1032. **    produced when the entire declaration is recognized by the "struct".
  1033. **
  1034. **
  1035. **        The state noted as
  1036. **            ® kSLex_Context kSLex_Decl kSLex_ParsedId •
  1037. **    occurs when a declaration has been seen the object being declared has
  1038. **    been seen.  The kSLex_ParsedId is shifted onto the stack *but is not displayed*
  1039. **    until more information has been passed in and we can decide how to display
  1040. **    the item.
  1041. **
  1042. **
  1043. **    (13)    ® kSLex_Context kSLex_Decl • kSLex_ParsedId    -> ® kSLex_Context kSLex_Decl kSLex_ParsedId •
  1044. **    The identifier might be the name of a type or it might be what is
  1045. **    being declared.
  1046. **
  1047. **
  1048. **    (16)    ® kSLex_Context kSLex_Decl • "{"        -> ® kSLex_Context kSLex_Decl "(" ")" • "{"
  1049. **    Assume that kSLex_Decl was a function header and that the body of the
  1050. **    function follows.
  1051. **
  1052. **
  1053. **    (17)    ® kSLex_Context kSLex_Decl • "("        -> ® kSLex_Context kSLex_Decl "(" kSLex_Context kSPrs_Decl •
  1054. **    Parse the argument list of a function declaration.
  1055. **
  1056. **
  1057. **    (18)    ® kSLex_Context kSLex_Decl "(" kSLex_Context kSPrs_Decl • ")"    -> ® kSLex_Context kSLex_Decl "(" ")" •
  1058. **    (19)    ® kSLex_Context kSLex_Decl "(" kSLex_Context kSPrs_Decl • ","    -> ® kSLex_Context kSLex_Decl "(" kSPrs_Decl •
  1059. **    Reduce a topmost parenthesized expression to a function header.  The
  1060. **    function header can then be followed by constructor initializers
  1061. **    (such as :BaseClass() ,field(value) {initStmt;})
  1062. **
  1063. **
  1064. **    (20)    ® kSLex_Context kSLex_Decl "(" ")" • "const        -> ® kSLex_Context kSLex_Decl "(" ")" •
  1065. **    (21)    ® kSLex_Context kSLex_Decl "(" ")" • "volatile"    -> ® kSLex_Context kSLex_Decl "(" ")" •
  1066. **    (22)    ® kSLex_Context kSLex_Decl "(" ")" • kSLex_Op    -> ® kSLex_Context kSLex_Decl • kSLex_Op
  1067. **    (23)    ® kSLex_Context kSLex_Decl "(" ")" • ";"        -> ® kSLex_Context kSLex_Decl • ";"
  1068. **    (24)    ® kSLex_Context kSLex_Decl "(" ")" • ","        -> ® kSLex_Context kSLex_Decl • ","
  1069. **    (25)    ® kSLex_Context kSLex_Decl "(" ")" • "{"        -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context "{" kSPrs_StmtList •
  1070. **    (26)    ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context "{" kSPrs_StmtList • "}" -> • kSPrs_Decl
  1071. **    After the header has been parsed, parse the body.  This handles function
  1072. **    prototypes.  A "® kSLex_Context kSLex_Decl "(" ")" "{" kSPrs_DeclList •"
  1073. **    is left on the stack while parsing the body of the function.  When the "}"
  1074. **    comes, we have a declaration and reduce to one.
  1075. **
  1076. **
  1077. **    (27)    ® kSLex_Context kSLex_Decl "(" ")" • kSLex_Decl        -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context kSPrs_DeclList • kSLex_Decl
  1078. **    (27)    ® kSLex_Context kSLex_Decl "(" ")" • "struct"        -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context kSPrs_DeclList • "struct"
  1079. **    (28)    ® kSLex_Context kSLex_Decl "(" ")" • kSLex_ParsedId    -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context kSPrs_DeclList • kSLex_ParsedId
  1080. **    (29)    ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context kSPrs_DeclList • "{"    -> ® kSLex_Context kSLex_Decl "(" ")" • "{"
  1081. **    This handles "old-style" C declarations, hence parse them as a DeclList
  1082. **    until the opening "{" is parsed.  Note that there is conflict with "const"
  1083. **    and "volatile" above.  This cannot be helped, so the decision is to move
  1084. **    "const" and "volatile" to the function header, as they were not keywords in
  1085. **    pre-ANSI C.
  1086. **
  1087. **
  1088. **    (30)    ® kSLex_Context kSLex_Decl "(" ")" • ":"    -> ® kSLex_Context kSLex_Decl "(" ")" ":" kSLex_Context kSPrs_Expr •
  1089. **    (31)    ® kSLex_Context kSLex_Decl "(" ")" ":" kSLex_Context kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Decl "(" ")" ":" kSLex_Context kSPrs_Expr •
  1090. **    (32)    ® kSLex_Context kSLex_Decl "(" ")" ":" kSLex_Context kSPrs_Expr • "{"    -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context "{" kSPrs_StmtList •
  1091. **    Constructors are function headers followed by initialization expressions and
  1092. **    a body.
  1093. **
  1094. **
  1095. **    (37)    ® kSLex_Context kSLex_Decl "(" ")" • "("    -> ® kSLex_Context kSLex_Decl • "("
  1096. **    What we thought was a function header wasn't.  It could have been the
  1097. **    declaration of a pointer to a function, such as "void (*foo)(...)".  Shift
  1098. **    to function declaration mode again.
  1099. **
  1100. **
  1101. **    (38)    ® kSLex_Context kSLex_Decl "(" ")" • ???    -> ® kSLex_Context kSLex_Decl • ???
  1102. **    Treat this as the end of a declaration.  Reduce and pass the information
  1103. **    upstream.
  1104. **
  1105. **
  1106. **    (33)    ® kSLex_Context kSLex_Decl • kSLex_Op    -> ® kSLex_Context kSLex_Decl kSLex_Op •
  1107. **    (34)    ? kSLex_Op • kSLex_Op                    -> ? kSLex_Op kSLex_Op •
  1108. **    (35)    ? kSLex_Op • kSLex_ParsedId                -> ? •
  1109. **    (36)    ? kSLex_Op • ???                        -> ? • ???
  1110. **    Operators are "*" and "&".  The "*" are counted until a terminating token
  1111. **    is scanned, at which point they are all removed from the stack.  The
  1112. **    operators are not displayed until they are removed.
  1113. **
  1114. **
  1115. **    (39)    ® kSLex_Context kSLex_Decl • kSLex_OpAssign                    -> ® kSLex_Context kSLex_Decl kSLex_OpAssign •
  1116. **    (40)    ® kSLex_Context kSLex_Decl kSLex_OpAssign • "{"                -> ® kSLex_Context kSLex_Decl kSLex_OpAssign kSLex_Context "{" kSPrs_Expr •
  1117. **    (41)    ® kSLex_Context kSLex_Decl kSLex_OpAssign • ???                -> ® kSLex_Context kSLex_Decl kSLex_OpAssign kSLex_Context kSPrs_Expr • ???
  1118. **    (42)    ® kSLex_Context kSLex_Decl kSLex_OpAssign kSLex_Context kSPrs_Expr • ???    -> ® kSLex_Context kSLex_Decl • ???
  1119. **    (44)    ® kSLex_Context kSLex_Decl kSLex_OpAssign kSLex_Context "{" kSPrs_Expr • "}"-> ® kSLex_Context kSLex_Decl •
  1120. **    (45)    ? kSLex_Context "{" kSPrs_Expr • "{"            -> ? kSLex_Context "{" kSPrs_Expr kSLex_Context "{" KSPrs_Expr •
  1121. **    (46)    ? kSLex_Context "{" kSPrs_Expr • "}"            -> ? •
  1122. **    (47)    ? kSLex_Context "{" kSPrs_Expr • ","            -> ? kSLex_Context "{" kSPrs_Expr •
  1123. **    (48)    ? kSLex_Context "{" kSPrs_Expr • kSPrs_Expr        -> ? kSLex_Context "{" kSPrs_Expr •
  1124. **    The other type of operator is the assignment operator, used for initializing
  1125. **    declared variables.  Note that if this is the initialization of a non-scalar
  1126. **    that nested initializations are possible.  The ? "{" ... "}" handle the
  1127. **    nesting.
  1128. **
  1129. **
  1130. **    (49)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • "("                -> ® kSLex_Context kSLex_Decl • "("
  1131. **    (70)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • "["                -> ® kSLex_Context kSLex_Decl • "["
  1132. **    (50)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ","                -> ® kSLex_Context kSLex_Decl • ","
  1133. **    (51)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ";"                -> ® kSLex_Context kSLex_Decl • ";"
  1134. **    (53)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • "}"                -> ® kSLex_Context kSLex_Decl • "}"
  1135. **    (68)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ")"                -> ® kSLex_Context kSLex_Decl • ")"
  1136. **    (54)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • kSLex_ParsedId    -> ® kSLex_Context kSLex_Decl kSLex_ParsedId •
  1137. **    (55)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • kSLex_Op        -> ® kSLex_Context kSLex_Decl • kSLex_Op
  1138. **    (56)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • kSLex_Decl        -> ® kSLex_Context kSLex_Decl •
  1139. **    When an identifier is on the stack in a "® kSLex_Context kSLex_Decl kSLex_ParsedId •",
  1140. **    it has not been written pending a resolution of what it is.  These rules do some
  1141. **    decisions about what it is.
  1142. **
  1143. **
  1144. **    (43)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ":"    -> ® kSLex_Context kSLex_Decl kSLex_Context kSPrs_Expr •
  1145. **    This is presumed to be a bitfield declaration.  Treat it as such.
  1146. **
  1147. **    (71)    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ???    -> ® kSLex_Context kSLex_Decl kSPrs_Expr • ???
  1148. **    Any other token type will shift us out of this phase and into a new one.  The
  1149. **    one exception is for source newlines, which will be passed along as required.
  1150. **
  1151. **
  1152. **    (57)    ® kSLex_Context kSLex_Decl • "["                                 -> ® kSLex_Context kSLex_Decl kSLex_Context "[" kSPrs_Expr •
  1153. **    (58)    ® kSLex_Context kSLex_Decl kSLex_Context "[" kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Decl kSLex_Context "[" kSPrs_Expr •
  1154. **    (59)    ® kSLex_Context kSLex_Decl kSLex_Context "[" kSPrs_Expr • "]"    -> ® kSLex_Context kSLex_Decl •
  1155. **    Reduce bracketed expressions 
  1156. **
  1157. **
  1158. **    (72)    ® kSLex_Context kSLex_Decl • kSLex_Value                    -> ® kSLex_Context kSLex_Decl kSLex_Context kSPrs_Expr • kSLex_Value
  1159. **    (73)    ® kSLex_Context kSLex_Decl kSLex_Context kSPrs_Expr • ???    -> ® kSLex_Context kSLex_Decl • ???
  1160. **    The declaration might have an expression within it.  Consequently, do the
  1161. **    expression.  When the expression is finished, reduce to a kSLex_Decl and see
  1162. **    what happens
  1163. **
  1164. **
  1165. **    (60)    ? "(" • "("                                -> ? "(" "(" •
  1166. **    (61)    ? "(" • ")"                                -> ? •
  1167. **    (62)    ? "(" • "["                                -> ? "(" "[" •
  1168. **    (63)    ? "(" • ???                                -> ? "(" kSLex_Context kSPrs_Expr • ???
  1169. **    (64)    ? "(" kSLex_Context kSPrs_Expr • ")"    -> ? kSLex_ParsedId •
  1170. **    (65)    ? "(" kSLex_Context kSPrs_Expr • ","    -> ? "(" kSLex_Context kSPrs_Expr •
  1171. **    (66)    ? "(" kSLex_Context kSPrs_Decl • ")"    -> ? kSLex_ParsedId •
  1172. **    (67)    ? "(" kSLex_Context kSPrs_Decl • ","    -> ? "(" kSLex_Context kSPrs_Decl •
  1173. **    Balanced brackets are nested or removed from the stack.  Commas within
  1174. **    balanced brackets separate expressions and declarations.  These are done
  1175. **    last as they are least specific.
  1176. */
  1177. #pragma segment ParserActions
  1178. Boolean
  1179. PrsDecl::Accept(Syntactic* aToken, Parser* aParser)
  1180.     {
  1181.     Formatting* aFormat = aParser->GetFormatting();
  1182.     static const short handles[] =
  1183.         {
  1184.         //ƒ-
  1185.         26,    kSLex_RCurly,        8,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,    kSLex_Context,    kSLex_LCurly,    kSPrs_StmtList,
  1186.         31,    kSLex_Comma,        8,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,    kSLex_Colon,    kSLex_Context,    kSPrs_Expr,
  1187.         32,    kSLex_LCurly,        8,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,    kSLex_Colon,    kSLex_Context,    kSPrs_Expr,
  1188.         29,    kSLex_LCurly,        7,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,    kSLex_Context,    kSPrs_DeclList,
  1189.         44, kSLex_RCurly,        7,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_OpAssign,    kSLex_Context,    kSLex_LCurly,    kSPrs_Expr,
  1190.         18,    kSLex_RParen,        6,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_Context,    kSPrs_Decl,
  1191.         19,    kSLex_Comma,        6,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_Context,    kSPrs_Decl,
  1192.         58, kSLex_Comma,        6,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_Context,    kSLex_LBrace,    kSPrs_Expr,
  1193.         59, kSLex_RBrace,        6,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_Context,    kSLex_LBrace,    kSPrs_Expr,
  1194. //        20,    kSLex_DeclConst,    5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1195. //        21,    kSLex_DeclVolatile,    5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1196.         22,    kSLex_Op,            5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1197.         23,    kSLex_SemiColon,    5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1198.         24,    kSLex_Comma,        5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1199.         25,    kSLex_LCurly,        5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1200.         27,    kSLex_Decl,            5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1201.         27,    kSLex_Struct,        5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1202.         28,    kSLex_ParsedId,        5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1203.         30,    kSLex_Colon,        5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1204.         37,    kSLex_LParen,        5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1205.         40, kSLex_LCurly,        4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_OpAssign,
  1206.         43,    kSLex_Colon,        4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1207.         49,    kSLex_LParen,        4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1208.         50,    kSLex_Comma,        4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1209.         51,    kSLex_SemiColon,    4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1210.         53,    kSLex_RCurly,        4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1211.         54,    kSLex_ParsedId,        4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1212.         55,    kSLex_Op,            4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1213.         56,    kSLex_Decl,            4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1214.         68,    kSLex_RParen,        4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1215.         70,    kSLex_LBrace,        4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1216.          7, kSLex_SemiColon,    3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1217.          8, kSLex_Comma,        3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1218.          9, kSLex_RParen,        3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1219.         10, kSPrs_DeclType,        3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1220.         11, kSLex_Decl,            3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1221.         12, kSPrs_Decl,            3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1222.         13, kSLex_ParsedId,        3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1223.         15, kSLex_Struct,        3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1224.         16, kSLex_LCurly,        3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1225.         17, kSLex_LParen,        3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1226.         33, kSLex_Op,            3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1227. //        39, kSLex_OpAssign,        3,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,
  1228.         45, kSLex_LCurly,        3,    kSLex_Context,    kSLex_LCurly,    kSPrs_Expr,
  1229.         46, kSLex_RCurly,        3,    kSLex_Context,    kSLex_LCurly,    kSPrs_Expr,
  1230.         47, kSLex_Comma,        3,    kSLex_Context,    kSLex_LCurly,    kSPrs_Expr,
  1231.         48, kSPrs_Expr,            3,    kSLex_Context,    kSLex_LCurly,    kSPrs_Expr,
  1232.         57, kSLex_LBrace,        3,    kSPrs_Decl,        kSLex_Context,    kSLex_Decl,
  1233.         64, kSLex_RParen,        3,    kSLex_LParen,    kSLex_Context,    kSPrs_Expr,
  1234.         65, kSLex_Comma,        3,    kSLex_LParen,    kSLex_Context,    kSPrs_Expr,
  1235.         66, kSLex_RParen,        3,    kSLex_LParen,    kSLex_Context,    kSPrs_Decl,
  1236.         67, kSLex_Comma,        3,    kSLex_LParen,    kSLex_Context,    kSPrs_Decl,
  1237.         69, kSLex_RCurly,        3,    kSPrs_Decl,        kSLex_Context,    kSLex_Decl,
  1238.         72, kSLex_Value,        3,    kSPrs_Decl,        kSLex_Context,    kSLex_Decl,
  1239.          6,    kSLex_Decl,            2,    kSPrs_Decl,        kSLex_OpBNot,
  1240.          0,    kSLex_SemiColon,    1,    kSPrs_Decl,
  1241.          1,    kSPrs_Decl,            1,    kSPrs_Decl,
  1242.          2,    kSLex_Struct,        1,    kSPrs_Decl,
  1243.          3,    kSLex_ParsedId,        1,    kSPrs_Decl,
  1244.          4,    kSLex_Decl,            1,    kSPrs_Decl,
  1245.          5,    kSLex_Op,            1,    kSPrs_Decl,
  1246.         76,    kSLex_Ellipsis,        1,    kSPrs_Decl,
  1247.         74, kSLex_Value,        1,    kSPrs_Decl,
  1248.         34, kSLex_Op,            1,    kSLex_Op,
  1249.         35, kSLex_ParsedId,        1,    kSLex_Op,
  1250.         60,    kSLex_LParen,        1,    kSLex_LParen,
  1251.         61,    kSLex_RParen,        1,    kSLex_LParen,
  1252.         62, kSLex_LBrace,        1,    kSLex_LParen,
  1253.         42, -1,                    6,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_OpAssign,    kSLex_Context,    kSPrs_Expr,
  1254.         38,    -1,                    5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_LParen,    kSLex_RParen,
  1255.         73, -1,                    5,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_Context,    kSPrs_Expr,
  1256.         41, -1,                    4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_OpAssign,
  1257.         71, -1,                    4,    kSPrs_Decl,    kSLex_Context,    kSLex_Decl,    kSLex_ParsedId,
  1258.         75,    -1,                    3,    kSPrs_Decl,    kSLex_Context,    kSPrs_Expr,
  1259.         14,    -1,                    2,    kSPrs_Decl,    kSLex_OpBNot,
  1260.         36, -1,                    1,    kSLex_Op,
  1261.         63, -1,                    1,    kSLex_LParen,
  1262.  
  1263.         -1, -1,                    0
  1264.         //ƒ+
  1265.         };
  1266.  
  1267.     /*
  1268.     ** Hack.  Various states are hidden under other states.
  1269.     **
  1270.     **        ( 5)    ->    (52)
  1271.     **            The operator might a "~", part of a destructor name.
  1272.     **
  1273.     **        (27)    ->    (20)
  1274.     **        (27)    ->    (21)
  1275.     **            Both "const" and "volatile" are MinorType()s of kSLex_Decl.
  1276.     **
  1277.     **        (33)    ->    (39)
  1278.     **            The kSLex_Op might be a kSLex_OpAssign.
  1279.     **
  1280.     ** Check the type of aToken and modify the state index.
  1281.     */
  1282.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  1283.     switch (anIndex)
  1284.         {
  1285.     case  5:
  1286.         if (aToken->MinorType() == kSLex_OpBNot)
  1287.             anIndex = 52;
  1288.         break;
  1289.         
  1290.     case 27:
  1291.         switch (aToken->MinorType())
  1292.             {
  1293.         case kSLex_DeclConst:        anIndex = 20;    break;
  1294.         case kSLex_DeclVolatile:    anIndex = 21;    break;
  1295.             }
  1296.         break;
  1297.         
  1298.     case 33:
  1299.         if (aToken->MinorType() == kSLex_OpAssign)
  1300.             anIndex = 39;
  1301.         break;
  1302.         }
  1303.  
  1304.     DEBUGPARSER(Decl, anIndex);
  1305.  
  1306.     switch (anIndex)
  1307.         {
  1308.     case  0:    //    ® • ";"                                -> • kSPrs_Decl
  1309.         aFormat->SetGlue(gFS_decl0);
  1310.         aFormat->Semi();
  1311.         aFormat->Display(aToken);
  1312.         aParser->Reduce(this, 1);
  1313.         break;
  1314.  
  1315.     case  1:    //    ® • kSPrs_Decl                        -> • kSPrs_Decl
  1316.         aParser->Reduce(aToken, 1);
  1317.         break;
  1318.  
  1319.     case  2:    //    ® • "struct"                        -> ® kSLex_Context kSLex_Decl kSPrs_Struct • "struct"
  1320.         aFormat->OpenContext();
  1321.         DEBUGSETCONTEXT(setDeclContext)
  1322.         setDeclContext(aFormat);
  1323.         aParser->Shift(&gContext);
  1324.         aParser->Shift(&gLexDecl);
  1325.         aParser->Shift(&gPrsStruct);
  1326.         aParser->Parse(aToken);
  1327.         break;
  1328.  
  1329.     case  3:    //    ® • kSLex_ParsedId                    -> ® kSLex_Context kSLex_Decl •
  1330.     case  4:    //    ® • kSLex_Decl                        -> ® kSLex_Context kSLex_Decl •
  1331.     case 76:    //    ® • kSLex_Ellipsis                    -> ® kSLex_Context kSLex_Decl •
  1332.         aFormat->OpenContext();
  1333.         DEBUGSETCONTEXT(setDeclContext)
  1334.         setDeclContext(aFormat);
  1335.         aFormat->SetGlue(gFS_decl0);
  1336.         aFormat->Name();
  1337.         aFormat->Display(aToken);
  1338.         aParser->Shift(&gContext);
  1339.         aParser->Shift(&gLexDecl);
  1340.         break;
  1341.  
  1342.     case  5:    //    ® • kSLex_Op                        -> ® kSLex_Context kSLex_Decl •
  1343.         aFormat->OpenContext();
  1344.         DEBUGSETCONTEXT(setDeclContext)
  1345.         setDeclContext(aFormat);
  1346.         aFormat->SetGlue(gFS_decl0);
  1347.         aParser->Shift(&gContext);
  1348.         aParser->Shift(&gLexDecl);
  1349.         return (Accept(aToken, aParser));
  1350.  
  1351.     case 52:    //    ® • kSLex_OpBNot                    -> ® kSLex_OpBNot •
  1352.         aParser->Shift(&gLexBNot);
  1353.         break;
  1354.  
  1355.     case  6:    //    ® kSLex_OpBNot • kSLex_ParsedId        -> ® kSLex_Context kSLex_Decl kSLex_ParsedId •
  1356.         aFormat->OpenContext();
  1357.         DEBUGSETCONTEXT(setDeclContext)
  1358.         setDeclContext(aFormat);
  1359.         aFormat->SetGlue(gFS_decl0);
  1360.         aParser->TopItem(&gContext);
  1361.         aParser->Shift(&gLexDecl);
  1362.         aParser->Shift(new PrsDestructor(aToken));
  1363.         break;
  1364.  
  1365.     case 14:    //    ® kSLex_OpBNot • ???                -> ® kSLex_Context kSLex_Decl • ???
  1366.         if (aToken->IsSeparator())
  1367.             {
  1368.             aFormat->Display(aToken);
  1369.             return (true);
  1370.             }
  1371.         aFormat->OpenContext();
  1372.         DEBUGSETCONTEXT(setDeclContext)
  1373.         setDeclContext(aFormat);
  1374.         aFormat->SetGlue(gFS_decl0);
  1375.         aFormat->Display(aParser->TopItem());
  1376.         aParser->TopItem(&gContext);
  1377.         aParser->Shift(&gLexDecl);
  1378.         return (Accept(aToken, aParser));
  1379.  
  1380.     case 74:    //    ® • kSLex_Value                        -> ® kSLex_Context kSPrs_Expr • kSLex_Value
  1381.         aFormat->OpenContext();
  1382.         DEBUGSETCONTEXT(setExprContext)
  1383.         setExprContext(aFormat);
  1384.         aFormat->SetGlue(gFS_decl0);
  1385.         aParser->Shift(&gContext);
  1386.         aParser->Shift(&gPrsExpr);
  1387.         aParser->Parse(aToken);
  1388.         break;
  1389.  
  1390.     case 75:    //    ® kSLex_Context kSPrs_Expr • ???    -> ® kSLex_Context kSLex_Decl • ???
  1391.         if (aToken->IsSeparator())
  1392.             {
  1393.             aFormat->Display(aToken);
  1394.             return (true);
  1395.             }
  1396.         aFormat->RestoreIndent();
  1397.         DEBUGSETCONTEXT(setDeclContext)
  1398.         setDeclContext(aFormat);
  1399.         aParser->TopItem(&gLexDecl);
  1400.         return (Accept(aToken, aParser));
  1401.  
  1402.     case  7:    //    ® kSLex_Context kSLex_Decl • ";"    -> ® • kSPrs_Decl
  1403.         aFormat->SetGlue(gFS_decl10);
  1404.         aFormat->Display(aToken);
  1405.         aFormat->CloseContext();
  1406.         aParser->Drop(2);
  1407.         return (Accept(&gPrsDecl, aParser));
  1408.  
  1409.     case  8:    //    ® kSLex_Context kSLex_Decl • ","    -> ® • ","
  1410.     case  9:    //    ® kSLex_Context kSLex_Decl • ")"    -> ® • ")"
  1411.     case 69:    //    ® kSLex_Context kSLex_Decl • "}"    -> ® • "}"
  1412.         aFormat->CloseContext();
  1413.         aParser->Drop(2);
  1414.         return (Accept(aToken, aParser));
  1415.  
  1416.     case 10:    //    ® kSLex_Context kSLex_Decl • kSPrs_DeclType        -> ® kSLex_Context kSLex_Decl •
  1417.         break;
  1418.  
  1419.     case 11:    //    ® kSLex_Context kSLex_Decl • kSLex_Decl            -> ® kSLex_Context kSLex_Decl •
  1420.         aFormat->Name();
  1421.         aFormat->Display(aToken);
  1422.         break;
  1423.  
  1424.     case 12:    //    ® kSLex_Context kSLex_Decl • kSPrs_Decl            -> ® • kSPrs_Decl
  1425.         aFormat->CloseContext();
  1426.         aParser->Drop(2);
  1427.         return (Accept(aToken, aParser));
  1428.  
  1429.     case 15:    //    ® kSLex_Context kSLex_Decl • "struct"            -> ® • "struct"
  1430.         aFormat->Name();
  1431.         aFormat->CloseContext();
  1432.         aParser->Drop(2);
  1433.         return (Accept(aToken, aParser));
  1434.  
  1435.     case 13:    //    ® kSLex_Context kSLex_Decl • kSLex_ParsedId    -> ® kSLex_Context kSLex_Decl kSLex_ParsedId •
  1436.         aParser->Shift(aToken);
  1437.         break;
  1438.  
  1439.     case 16:    //    ® kSLex_Context kSLex_Decl • "{"        -> ® kSLex_Context kSLex_Decl "(" ")" • "{"
  1440.         aFormat->RestoreIndent();
  1441.         aParser->Shift(&gLexLParen);
  1442.         aParser->Shift(&gLexRParen);
  1443.         return (Accept(aToken, aParser));
  1444.  
  1445.     case 17:    //    ® kSLex_Context kSLex_Decl • "("        -> ® kSLex_Context kSLex_Decl "(" kSLex_Context kSPrs_Decl •
  1446.         aFormat->RestoreIndent();
  1447.         aFormat->OpenContext();
  1448.         DEBUGSETCONTEXT(setDeclContext)
  1449.         setDeclContext(aFormat);
  1450.         aFormat->SetGlue(gFS_fundef3);
  1451.         aFormat->Display(aToken);
  1452.         aParser->Shift(aToken);
  1453.         aParser->Shift(&gContext);
  1454.         aParser->Shift(&gPrsDecl);
  1455.         break;
  1456.  
  1457.     case 18:    //    ® kSLex_Context kSLex_Decl "(" kSLex_Context kSPrs_Decl • ")"    -> ® kSLex_Context kSLex_Decl "(" ")" •
  1458.         aFormat->SetGlue(gFS_fundef6);
  1459.         aFormat->Display(aToken);
  1460.         aFormat->CloseContext();
  1461.         aParser->Drop(2);
  1462.         aParser->Shift(aToken);
  1463.         break;
  1464.  
  1465.     case 19:    //    ® kSLex_Context kSLex_Decl "(" kSLex_Context kSPrs_Decl • ","    -> ® kSLex_Context kSLex_Decl "(" kSPrs_Decl •
  1466.         aFormat->SetGlue(gFS_fundef4);
  1467.         aFormat->Display(aToken);
  1468.         break;
  1469.  
  1470.     case 20:    //    ® kSLex_Context kSLex_Decl "(" ")" • "const        -> ® kSLex_Context kSLex_Decl "(" ")" •
  1471.     case 21:    //    ® kSLex_Context kSLex_Decl "(" ")" • "volatile"    -> ® kSLex_Context kSLex_Decl "(" ")" •
  1472.         aFormat->SetGlue((FormatString)"!n s# •");
  1473.         aFormat->Display(aToken);
  1474.         break;
  1475.  
  1476.     case 22:    //    ® kSLex_Context kSLex_Decl "(" ")" • kSLex_Op    -> ® kSLex_Context kSLex_Decl • kSLex_Op
  1477.     case 23:    //    ® kSLex_Context kSLex_Decl "(" ")" • ";"        -> ® kSLex_Context kSLex_Decl • ";"
  1478.     case 24:    //    ® kSLex_Context kSLex_Decl "(" ")" • ","        -> ® kSLex_Context kSLex_Decl • ","
  1479.         aParser->Drop(2);
  1480.         return (Accept(aToken, aParser));
  1481.  
  1482.     case 25:    //    ® kSLex_Context kSLex_Decl "(" ")" • "{"        -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context "{" kSPrs_StmtList •
  1483.         aFormat->OpenContext();
  1484.         DEBUGSETCONTEXT(setFundefContext)
  1485.         setFundefContext(aFormat);
  1486.         aFormat->SetLCurly(gFS_fundef11);
  1487.         aFormat->SetRCurly(gFS_fundef12);
  1488.         aFormat->LCurly();
  1489.         aFormat->Display(aToken);
  1490.         aParser->Shift(&gContext);
  1491.         aParser->Shift(aToken);
  1492.         aParser->Shift(&gPrsStmtList);
  1493.         break;
  1494.  
  1495.     case 26:    //    ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context "{" kSPrs_StmtList • "}" -> • kSPrs_Decl
  1496.         aFormat->RCurly();
  1497.         aFormat->Display(aToken);
  1498.         aFormat->CloseContext();
  1499.         aFormat->CloseContext();
  1500.         aParser->Reduce(&gPrsDecl, 7);
  1501.         break;
  1502.  
  1503.     case 27:    //    ® kSLex_Context kSLex_Decl "(" ")" • kSLex_Decl        -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context kSPrs_DeclList • kSLex_Decl
  1504. //    case 27:    //    ® kSLex_Context kSLex_Decl "(" ")" • "struct"        -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context kSPrs_DeclList • "struct"
  1505.     case 28:    //    ® kSLex_Context kSLex_Decl "(" ")" • kSLex_ParsedId    -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context kSPrs_DeclList • kSLex_ParsedId
  1506.         aFormat->RestoreIndent();
  1507.         aFormat->OpenContext();
  1508.         DEBUGSETCONTEXT(setDeclContext)
  1509.         setDeclContext(aFormat);
  1510.         aFormat->SetGlue(gFS_fundef7);
  1511.         aParser->Shift(&gContext);
  1512.         aParser->Shift(&gPrsDeclList);
  1513.         aParser->Parse(aToken);
  1514.         break;
  1515.  
  1516.     case 29:    //    ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context kSPrs_DeclList • "{"    -> ® kSLex_Context kSLex_Decl "(" ")" • "{"
  1517.         aFormat->CloseContext();
  1518.         aParser->Drop(2);
  1519.         return (Accept(aToken, aParser));
  1520.  
  1521.     case 30:    //    ® kSLex_Context kSLex_Decl "(" ")" • ":"    -> ® kSLex_Context kSLex_Decl "(" ")" ":" kSLex_Context kSPrs_Expr •
  1522.         aFormat->SetGlue(gFS_fundef8);
  1523.         aFormat->Display(aToken);
  1524.         aFormat->OpenContext();
  1525.         DEBUGSETCONTEXT(setExprContext)
  1526.         setExprContext(aFormat);
  1527.         aParser->Shift(aToken);
  1528.         aParser->Shift(&gContext);
  1529.         aParser->Shift(&gPrsExpr);
  1530.         break;
  1531.  
  1532.     case 31:    //    ® kSLex_Context kSLex_Decl "(" ")" ":" kSLex_Context kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Decl "(" ")" ":" kSLex_Context kSPrs_Expr •
  1533.         aFormat->RestoreIndent();
  1534.         aFormat->SetGlue(gFS_fundef10);
  1535.         aFormat->Display(aToken);
  1536.         break;
  1537.  
  1538.     case 32:    //    ® kSLex_Context kSLex_Decl "(" ")" ":" kSLex_Context kSPrs_Expr • "{"    -> ® kSLex_Context kSLex_Decl "(" ")" kSLex_Context "{" kSPrs_StmtList •
  1539.         aFormat->RestoreIndent();
  1540.         DEBUGSETCONTEXT(setFundefContext)
  1541.         setFundefContext(aFormat);
  1542.         aFormat->SetLCurly(gFS_fundef13);
  1543.         aFormat->SetRCurly(gFS_fundef14);
  1544.         aFormat->LCurly();
  1545.         aFormat->Display(aToken);
  1546.         aParser->Drop(3);
  1547.         aParser->Shift(&gContext);
  1548.         aParser->Shift(aToken);
  1549.         aParser->Shift(&gPrsStmtList);
  1550.         break;
  1551.  
  1552.     case 37:    //    ® kSLex_Context kSLex_Decl "(" ")" • "("    -> ® kSLex_Context kSLex_Decl • "("
  1553.     case 38:    //    ® kSLex_Context kSLex_Decl "(" ")" • ???    -> ® kSLex_Context kSLex_Decl • ???
  1554.         if (aToken->IsSeparator())
  1555.             {
  1556.             aFormat->Display(aToken);
  1557.             return (true);
  1558.             }
  1559.         aParser->Drop(2);
  1560.         return (Accept(aToken, aParser));
  1561.  
  1562.     case 33:    //    ® kSLex_Context kSLex_Decl • kSLex_Op    -> ® kSLex_Context kSLex_Decl kSLex_Op •
  1563.     case 34:    //    ? kSLex_Op • kSLex_Op                    -> ? kSLex_Op kSLex_Op •
  1564.         aParser->Shift(aToken);
  1565.         break;
  1566.  
  1567.     case 35:    //    ? kSLex_Op • kSLex_ParsedId                -> ? •
  1568.     case 36:    //    ? kSLex_Op • ???                        -> ? • ???
  1569.         {
  1570.         short nOperators = 0;
  1571.         
  1572.         while (aParser->Pick(nOperators)->Type() == kSLex_Op)
  1573.             nOperators++;
  1574.  
  1575.         // if the token is a right paren, this declaration is most likely a
  1576.         // cast.  We don't make casts as wide as possible.  However, we might
  1577.         // want a space between the type and the operators, so we check
  1578.         // DeclLeft()
  1579.         if (aToken->Type() != kSLex_RParen)
  1580.             aFormat->DeclPadStart(nOperators);
  1581.         else if (!aFormat->DeclLeft())
  1582.             aFormat->ExecuteGlue((FormatString)"s#");
  1583.  
  1584.         short i = nOperators;
  1585.         while (i--)
  1586.             aFormat->Display(aParser->Pick(i));
  1587.  
  1588.         // If this is not a cast, then pad it out if required.
  1589.         if (aToken->Type() != kSLex_RParen)
  1590.             aFormat->DeclPadEnd();
  1591.         aParser->Drop(nOperators);
  1592.         }
  1593.         
  1594.         if (anIndex == 35)
  1595.             aFormat->Display(aToken);
  1596.         else
  1597.             return (Accept(aToken, aParser));
  1598.         break;
  1599.  
  1600.     case 39:    //    ® kSLex_Context kSLex_Decl • kSLex_OpAssign                    -> ® kSLex_Context kSLex_Decl kSLex_OpAssign •
  1601.         aFormat->SetGlue(gFS_decl2);
  1602.         aFormat->Display(aToken);
  1603.         aParser->Shift(&gLexOpAssign);
  1604.         break;
  1605.  
  1606.     case 40:    //    ® kSLex_Context kSLex_Decl kSLex_OpAssign • "{"                -> ® kSLex_Context kSLex_Decl kSLex_OpAssign kSLex_Context "{" kSPrs_Expr •
  1607.         aFormat->OpenContext();
  1608.         DEBUGSETCONTEXT(setExprContext)
  1609.         setExprContext(aFormat);
  1610.         aFormat->SetGlue(gFS_decl5);
  1611.         aFormat->Display(aToken);
  1612.         aParser->Shift(&gContext);
  1613.         aParser->Shift(aToken);
  1614.         aParser->Shift(&gPrsExpr);
  1615.         break;
  1616.  
  1617.     case 41:    //    ® kSLex_Context kSLex_Decl kSLex_OpAssign • ???                -> ® kSLex_Context kSLex_Decl kSLex_OpAssign kSLex_Context kSPrs_Expr • ???
  1618.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  1619.             {
  1620.             aParser->Shift(&gPrsNewLine);
  1621.             return (true);
  1622.             }
  1623.         if (aToken->IsSeparator())
  1624.             {
  1625.             aFormat->Display(aToken);
  1626.             return (true);
  1627.             }
  1628.         aFormat->OpenContext();
  1629.         DEBUGSETCONTEXT(setExprContext)
  1630.         setExprContext(aFormat);
  1631.         aParser->Shift(&gContext);
  1632.         aParser->Shift(&gPrsExpr);
  1633.         aParser->Parse(aToken);
  1634.         break;
  1635.  
  1636.     case 42:    //    ® kSLex_Context kSLex_Decl kSLex_OpAssign kSLex_Context kSPrs_Expr • ???    -> ® kSLex_Context kSLex_Decl • ???
  1637.         if (aToken->IsSeparator())
  1638.             {
  1639.             aFormat->Display(aToken);
  1640.             return (true);
  1641.             }
  1642.         aFormat->CloseContext();
  1643.         aParser->Drop(3);
  1644.         return (Accept(aToken, aParser));
  1645.  
  1646.     case 44:    //    ® kSLex_Context kSLex_Decl kSLex_OpAssign kSLex_Context "{" kSPrs_Expr • "}"-> ® kSLex_Context kSLex_Decl •
  1647.         aFormat->SetGlue(gFS_decl9);
  1648.         aFormat->Display(aToken);
  1649.         aFormat->CloseContext();
  1650.         aParser->Drop(4);
  1651.         break;
  1652.  
  1653.     case 45:    //    ? kSLex_Context "{" kSPrs_Expr • "{"            -> ? kSLex_Context "{" kSPrs_Expr kSLex_Context "{" KSPrs_Expr •
  1654.         aFormat->OpenContext();
  1655.         aFormat->SetGlue(gFS_decl6);
  1656.         aFormat->Display(aToken);
  1657.         aParser->Shift(&gContext);
  1658.         aParser->Shift(aToken);
  1659.         aParser->Shift(&gPrsExpr);
  1660.         break;
  1661.  
  1662.     case 46:    //    ? kSLex_Context "{" kSPrs_Expr • "}"            -> ? •
  1663.         aFormat->SetGlue(gFS_decl7);
  1664.         aFormat->Display(aToken);
  1665.         aFormat->CloseContext();
  1666.         aParser->Drop(3);
  1667.         break;
  1668.  
  1669.     case 47:    //    ? kSLex_Context "{" kSPrs_Expr • ","            -> ? kSLex_Context "{" kSPrs_Expr •
  1670.         aFormat->SetGlue(gFS_decl8);
  1671.         aFormat->Display(aToken);
  1672.         break;
  1673.  
  1674.     case 48:    //    ? kSLex_Context "{" kSPrs_Expr • kSPrs_Expr        -> ? kSLex_Context "{" kSPrs_Expr •
  1675.         break;
  1676.  
  1677.     case 49:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • "("                -> ® kSLex_Context kSLex_Decl • "("
  1678.     case 70:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • "["                -> ® kSLex_Context kSLex_Decl • "["
  1679.     case 50:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ","                -> ® kSLex_Context kSLex_Decl • ","
  1680.     case 51:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ";"                -> ® kSLex_Context kSLex_Decl • ";"
  1681.     case 53:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • "}"                -> ® kSLex_Context kSLex_Decl • "}"
  1682.     case 68:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ")"                -> ® kSLex_Context kSLex_Decl • ")"
  1683.         aFormat->Name();
  1684.         aFormat->Display(aParser->TopItem());
  1685.         aParser->Drop(1);
  1686.         return (Accept(aToken, aParser));
  1687.  
  1688.     case 54:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • kSLex_ParsedId    -> ® kSLex_Context kSLex_Decl kSLex_ParsedId •
  1689.         aFormat->Name();
  1690.         aFormat->Display(aParser->TopItem());
  1691.         aParser->TopItem(aToken);
  1692.         break;
  1693.  
  1694.     case 55:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • kSLex_Op        -> ® kSLex_Context kSLex_Decl • kSLex_Op
  1695.         aFormat->Name();
  1696.         aFormat->Display(aParser->TopItem());
  1697.         aParser->Drop(1);
  1698.         return (Accept(aToken, aParser));
  1699.  
  1700.     case 56:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • kSLex_Decl    -> ® kSLex_Context kSLex_Decl •
  1701.         aFormat->Name();
  1702.         aFormat->Display(aParser->TopItem());
  1703.         aFormat->Name();
  1704.         aFormat->Display(aToken);
  1705.         aParser->Drop(1);
  1706.         break;
  1707.  
  1708.     case 43:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ":"    -> ® kSLex_Context kSLex_Decl kSLex_Context kSPrs_Expr •
  1709.         aFormat->Name();
  1710.         aFormat->Display(aParser->TopItem());
  1711.         aFormat->Display(aToken);
  1712.         aFormat->OpenContext();
  1713.         DEBUGSETCONTEXT(setExprContext)
  1714.         setExprContext(aFormat);
  1715.         aParser->TopItem(&gContext);
  1716.         aParser->Shift(&gPrsExpr);
  1717.         break;
  1718.  
  1719.     case 71:    //    ® kSLex_Context kSLex_Decl kSLex_ParsedId • ???    -> ® kSLex_Context kSLex_Decl kSPrs_Expr • ???
  1720.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  1721.             {
  1722.             aParser->Shift(&gPrsNewLine);
  1723.             return (true);
  1724.             }
  1725.         aFormat->Name();
  1726.         aFormat->Display(aParser->TopItem());
  1727.         aParser->Drop(1);
  1728.         return (Accept(aToken, aParser));
  1729.  
  1730.     case 57:    //    ® kSLex_Context kSLex_Decl • "["                                 -> ® kSLex_Context kSLex_Decl kSLex_Context "[" kSPrs_Expr •
  1731.         aFormat->OpenContext();
  1732.         DEBUGSETCONTEXT(setExprContext)
  1733.         setExprContext(aFormat);
  1734.         aFormat->LParen();
  1735.         aFormat->Display(aToken);
  1736.         aParser->Shift(&gContext);
  1737.         aParser->Shift(aToken);
  1738.         aParser->Shift(&gPrsExpr);
  1739.         break;
  1740.  
  1741.     case 58:    //    ® kSLex_Context kSLex_Decl kSLex_Context "[" kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Decl kSLex_Context "[" kSPrs_Expr •
  1742.         aFormat->Comma();
  1743.         aFormat->Display(aToken);
  1744.         break;
  1745.  
  1746.     case 59:    //    ® kSLex_Context kSLex_Decl kSLex_Context "[" kSPrs_Expr • "]"    -> ® kSLex_Context kSLex_Decl •
  1747.         aFormat->RParen();
  1748.         aFormat->Display(aToken);
  1749.         aFormat->CloseContext();
  1750.         aParser->Drop(3);
  1751.         break;
  1752.  
  1753.     case 72:    //    ® kSLex_Context kSLex_Decl • kSLex_Value                    -> ® kSLex_Context kSLex_Decl kSLex_Context kSPrs_Expr • kSLex_Value
  1754.         aFormat->OpenContext();
  1755.         DEBUGSETCONTEXT(setExprContext)
  1756.         setExprContext(aFormat);
  1757.         aParser->Shift(&gContext);
  1758.         aParser->Shift(&gPrsExpr);
  1759.         aParser->Parse(aToken);
  1760.         break;
  1761.  
  1762.     case 73:    //    ® kSLex_Context kSLex_Decl kSLex_Context kSPrs_Expr • ???    -> ® kSLex_Context kSLex_Decl • ???
  1763.         if (aToken->IsSeparator())
  1764.             {
  1765.             aFormat->Display(aToken);
  1766.             return (true);
  1767.             }
  1768.         aFormat->CloseContext();
  1769.         aParser->Drop(2);
  1770.         return (Accept(aToken, aParser));
  1771.  
  1772.     case 61:    //    ? "(" • ")"                                -> ? •
  1773.         aFormat->RParen();
  1774.         aFormat->Display(aToken);
  1775.         aParser->Drop(1);
  1776.         break;
  1777.  
  1778.     case 60:    //    ? "(" • "("                                -> ? "(" "(" •
  1779.     case 62:    //    ? "(" • "["                                -> ? "(" "[" •
  1780.         aFormat->LParen();
  1781.         aFormat->Display(aToken);
  1782.         aParser->Shift(aToken);
  1783.         break;
  1784.  
  1785.     case 63:    //    ? "(" • ???                                -> ? "(" kSLex_Context kSPrs_Expr • ???
  1786.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  1787.             {
  1788.             aParser->Shift(&gPrsNewLine);
  1789.             return (true);
  1790.             }
  1791.         if (aToken->IsSeparator())
  1792.             {
  1793.             aFormat->Display(aToken);
  1794.             return (true);
  1795.             }
  1796.         aFormat->OpenContext();
  1797.         DEBUGSETCONTEXT(setExprContext)
  1798.         setExprContext(aFormat);
  1799.         aParser->Shift(&gContext);
  1800.         aParser->Shift(&gPrsExpr);
  1801.         aParser->Parse(aToken);
  1802.         break;
  1803.  
  1804.     case 64:    //    ? "(" kSLex_Context kSPrs_Expr • ")"    -> ? kSLex_ParsedId •
  1805.     case 66:    //    ? "(" kSLex_Context kSPrs_Decl • ")"    -> ? kSLex_ParsedId •
  1806.         aFormat->RParen();
  1807.         aFormat->Display(aToken);
  1808.         aFormat->CloseContext();
  1809.         aParser->Drop(3);
  1810.         aParser->Shift(&gLexParsedId);
  1811.         break;
  1812.  
  1813.     case 65:    //    ? "(" kSLex_Context kSPrs_Expr • ","    -> ? "(" kSLex_Context kSPrs_Expr •
  1814.         aFormat->Comma();
  1815.         aFormat->Display(aToken);
  1816.         break;
  1817.  
  1818.     case 67:    //    ? "(" kSLex_Context kSPrs_Decl • ","    -> ? "(" kSLex_Context kSPrs_Decl •
  1819.         aFormat->Comma();
  1820.         aFormat->Display(aToken);
  1821.         break;
  1822.  
  1823.     default:
  1824.         if (aToken->IsSeparator())
  1825.             {
  1826.             aFormat->Display(aToken);
  1827.             return (true);
  1828.             }
  1829.         return (false);
  1830.         }
  1831.         
  1832.     return (true);
  1833.     }
  1834.  
  1835.  
  1836. /*µ kSPrs_Do    ( 9)
  1837. **    ( 0)    ® • "do"                    -> ® kSLex_Context •
  1838. **
  1839. **    ( 1)    ® kSLex_Context • ";"        -> ® kSLex_Context ";" •
  1840. **    ( 2)    ® kSLex_Context • "{"        -> ® kSLex_Context "{" kSPrs_StmtList •
  1841. **    ( 3)    ® kSLex_Context • ???        -> ® kSLex_Context ";" kSPrs_Stmt • ???
  1842. **
  1843. **    ( 4)    ® kSLex_Context "{" kSPrs_StmtList • "}"    -> ® kSLex_Context ";"
  1844. **
  1845. **    ( 5)    ® kSLex_Context ";" • kSPrs_Stmt    -> ® kSLex_Context ";" •
  1846. **    ( 6)    ® kSLex_Context ";" • "while"        -> ® kSLex_Context "while" •
  1847. **
  1848. **    ( 7)    ® kSLex_Context "while" • "("        -> ® kSLex_Context "(" kSPrs_Expr •
  1849. **
  1850. **    ( 8)    ® kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_Context ")" •
  1851. **
  1852. **    ( 9)    ® kSLex_Context ")" • ";"                -> • kSPrs_Stmt
  1853. **
  1854. **    Emit the "do" (0) and the statement following it (1) and (2).  After the
  1855. ** statement has been parsed (3), wait for the "while" (4), the "(" (5), the
  1856. ** conditional expression and closing ")" (6) and the close ";" (7)
  1857. */
  1858. #pragma segment ParserActions
  1859. Boolean
  1860. PrsDo::Accept(Syntactic* aToken, Parser* aParser)
  1861.     {
  1862.     Formatting* aFormat = aParser->GetFormatting();
  1863.     static const short handles[] =
  1864.         {
  1865.         //ƒ-
  1866.          8,    kSLex_RParen,        4,    kSPrs_Do,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  1867.          4,    kSLex_RCurly,        4,    kSPrs_Do,    kSLex_Context,    kSLex_LCurly,    kSPrs_StmtList,
  1868.          5,    kSPrs_Stmt,            3,    kSPrs_Do,    kSLex_Context,    kSLex_SemiColon,
  1869.          6,    kSLex_While,        3,    kSPrs_Do,    kSLex_Context,    kSLex_SemiColon,
  1870.          7,    kSLex_LParen,        3,    kSPrs_Do,    kSLex_Context,    kSLex_While,
  1871.          9,    kSLex_SemiColon,    3,    kSPrs_Do,    kSLex_Context,    kSLex_RParen,
  1872.          1,    kSLex_SemiColon,    2,    kSPrs_Do,    kSLex_Context,
  1873.          2,    kSLex_LCurly,        2,    kSPrs_Do,    kSLex_Context,
  1874.          0,    kSLex_Do,            1,    kSPrs_Do,
  1875.          3,    -1,                    2,    kSPrs_Do,    kSLex_Context,
  1876.          
  1877.         -1, -1,                    0
  1878.         //ƒ+
  1879.         };
  1880.  
  1881.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  1882.     DEBUGPARSER(Do, anIndex);
  1883.  
  1884.     switch (anIndex)
  1885.         {
  1886.     case  0:    //    ® • "do"                    -> ® kSLex_Context •
  1887.         aFormat->OpenContext();
  1888.         DEBUGSETCONTEXT(setExprContext)
  1889.         setExprContext(aFormat);
  1890.         aFormat->SetGlue(gFS_do0);
  1891.         aFormat->Display(aToken);
  1892.         aParser->Shift(&gContext);
  1893.         break;
  1894.  
  1895.     case  1:    //    ® kSLex_Context • ";"        -> ® kSLex_Context ";" •
  1896.         aFormat->SetGlue(gFS_do1);
  1897.         aFormat->Display(aToken);
  1898.         aParser->TopItem(&gLexSemiColon);
  1899.         break;
  1900.  
  1901.     case  2:    //    ® kSLex_Context • "{"        -> ® kSLex_Context "{" kSPrs_StmtList •
  1902.         aFormat->SetGlue(gFS_do2);
  1903.         aFormat->Display(aToken);
  1904.         aParser->Shift(aToken);
  1905.         aParser->Shift(&gPrsStmtList);
  1906.         break;
  1907.  
  1908.     case  3:    //    ® kSLex_Context • ???        -> ® kSLex_Context ";" kSPrs_Stmt • ???
  1909.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  1910.             {
  1911.             aParser->Shift(&gPrsNewLine);
  1912.             return (true);
  1913.             }
  1914.         if (aToken->IsSeparator())
  1915.             {
  1916.             aFormat->Display(aToken);
  1917.             return (true);
  1918.             }
  1919.         aFormat->SetGlue(gFS_do3);
  1920.         aParser->Shift(&gLexSemiColon);
  1921.         aParser->Shift(&gPrsStmt);
  1922.         aParser->Parse(aToken);
  1923.         break;
  1924.  
  1925.     case  4:    //    ® kSLex_Context "{" kSPrs_StmtList • "}"    -> ® kSLex_Context ";"
  1926.         aFormat->SetGlue(gFS_do4);
  1927.         aFormat->Display(aToken);
  1928.         aParser->Drop(2);
  1929.         aParser->Shift(&gLexSemiColon);
  1930.         break;
  1931.  
  1932.     case  5:    //    ® kSLex_Context ";" • kSPrs_Stmt    -> ® kSLex_Context ";" •
  1933.         break;
  1934.  
  1935.     case  6:    //    ® kSLex_Context ";" • "while"        -> ® kSLex_Context "while" •
  1936.         aFormat->RestoreIndent();
  1937.         aFormat->SetGlue(gFS_do5);
  1938.         aFormat->Display(aToken);
  1939.         aParser->TopItem(aToken);
  1940.         break;
  1941.  
  1942.     case  7:    //    ® kSLex_Context "while" • "("        -> ® kSLex_Context "(" kSPrs_Expr •
  1943.         aFormat->SetGlue(gFS_do6);
  1944.         aFormat->Display(aToken);
  1945.         aParser->TopItem(aToken);
  1946.         aParser->Shift(&gPrsExpr);
  1947.         break;
  1948.  
  1949.     case  8:    //    ® kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_Context ")" •
  1950.         aFormat->RParen();
  1951.         aFormat->Display(aToken);
  1952.         aParser->Drop(2);
  1953.         aParser->Shift(aToken);
  1954.         break;
  1955.  
  1956.     case  9:    //    ® kSLex_Context ")" • ";"                -> • kSPrs_Stmt
  1957.         aFormat->Semi();
  1958.         aFormat->Display(aToken);
  1959.         aFormat->CloseContext();
  1960.         aParser->Reduce(&gPrsStmt, 3);
  1961.         break;
  1962.  
  1963.     default:
  1964.         if (aToken->IsSeparator())
  1965.             {
  1966.             aFormat->Display(aToken);
  1967.             return (true);
  1968.             }
  1969.         return (false);
  1970.         }
  1971.         
  1972.     return (true);
  1973.     }
  1974.  
  1975.  
  1976. /*µ kSPrs_If    (15)
  1977. **    ( 0)    ® • "if"                    -> ® kSLex_Context •
  1978. **    ( 1)    ® kSLex_Context • "("        -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr
  1979. **    ( 2)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr
  1980. **    ( 3)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_Context ")" •
  1981. **    (13)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • "{"    -> ® kSLex_Context ")" • "{"
  1982. **        Parse the "if ( expr )".  There should be a statement following.
  1983. **        The '® kSPrs_Expr • "{"' case is present because of a test case
  1984. **        where the closing paren was inside both parts of a #ifdef.  Thank
  1985. **        you very much.
  1986. **
  1987. **    ( 5)    ® kSLex_Context ")" • ";"            -> ® kSLex_Context ";" •
  1988. **        The statement following is empty.  Let it live.  Yield '® kSLex_Context ";"'
  1989. **        on the stack, indicating the then-part has been parse.  This indicates
  1990. **        that the then-part was not a compound statement.
  1991. **
  1992. **    ( 7)    ® kSLex_Context ")" • ???            -> ® kSLex_Context ")" kSLex_Context kSPrs_Stmt • ???
  1993. **    ( 6)    ® kSLex_Context ")" kSLex_Context • kSPrs_Stmt    -> ® kSLex_Context ";" •
  1994. **        Assume that this is some other sort of statement.  Upon completion,
  1995. **        indicate that the then-part has been parsed and that the then-part
  1996. **        was not a compound statement.
  1997. **
  1998. **    ( 4)    ® kSLex_Context ")" • "{"                                -> ® kSLex_Context kSLex_Context "{" kSPrs_StmtList •
  1999. **    ( 8)    ® kSLex_Context kSLex_Context "{" kSPrs_StmtList • "}"    -> ® kSLex_Context kSLex_Context "}" •
  2000. **        The statement following is a compound statement.  Yield '® kSLex_Context kSLex_Context "}"'
  2001. **        when the closing curly appears.  This indicates that the then-part was 
  2002. **        a compound statement.  An "else" following might be handled differently
  2003. **        than in cases (5) and (6).  Note that the "}" is not displayed, but
  2004. **        deferred until we know if an "else" or something else follows.
  2005. **
  2006. **    ( 9)    ® kSLex_Context ";" • "else"                    -> ® kSLex_Context ";" kSPrs_Else • "else"
  2007. **    (10)    ® kSLex_Context ";" • kSPrs_Else                -> • kSPrs_Stmt
  2008. **    (14)    ® kSLex_Context kSLex_Context "}" • "else"        -> ® kSLex_Context ";" kSPrs_Else • "else"
  2009. **    (12)    ® kSLex_Context ")" kSLex_Context kSPrs_Stmt • "else"    -> ® kSLex_Context ")" • kSPrs_Stmt "else"
  2010. **        The "else" part follows.  Use the kSPrs_Else object to parse "else"
  2011. **        and "else if" combinations.  When done, they yield a kSPrs_Else.
  2012. **        Again, because of macros, the kSPrs_Stmt might not appear.  When the
  2013. **        "else" keyword appears, assume the statement came through and handle
  2014. **        the "else".  Note that the ";" and "}" cases are distinguised because
  2015. **        of potentially different formatting in these cases.
  2016. **
  2017. **    (11)    ® kSLex_Context ";" • ???                    -> • kSPrs_Stmt ???
  2018. **    (15)    ® kSLex_Context kSLex_Context "}" • ???        -> ® kSLex_Context ";" • ???
  2019. **        If the then-part is followed by something other than a "else", reduce
  2020. **        the if to a statement and proceed.  If the then-part was a compound
  2021. **        statement, then convert to a normal statement and let the normal statement
  2022. **        mode handle the token.
  2023. */
  2024. #pragma segment ParserActions
  2025. Boolean
  2026. PrsIf::Accept(Syntactic* aToken, Parser* aParser)
  2027.     {
  2028.     Formatting* aFormat = aParser->GetFormatting();
  2029.     static const short handles[] =
  2030.         {
  2031.         //ƒ-
  2032.          8,    kSLex_RCurly,        5,    kSPrs_If,    kSLex_Context,    kSLex_Context,    kSLex_LCurly,    kSPrs_StmtList,
  2033.          2,    kSLex_Comma,        5,    kSPrs_If,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2034.          3,    kSLex_RParen,        5,    kSPrs_If,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2035.         12, kSLex_Else,            5,    kSPrs_If,    kSLex_Context,    kSLex_RParen,    kSLex_Context,    kSPrs_Stmt,
  2036.         13,    kSLex_LCurly,        5,    kSPrs_If,    kSLex_Context,    kSLex_Context,    kSLex_RParen,    kSPrs_Expr,
  2037.          6,    kSPrs_Stmt,            4,    kSPrs_If,    kSLex_Context,    kSLex_RParen,    kSLex_Context,
  2038.         14,    kSLex_Else,            4,    kSPrs_If,    kSLex_Context,    kSLex_Context,    kSLex_RCurly,
  2039.          4,    kSLex_LCurly,        3,    kSPrs_If,    kSLex_Context,    kSLex_RParen,
  2040.          5,    kSLex_SemiColon,    3,    kSPrs_If,    kSLex_Context,    kSLex_RParen,
  2041.          9,    kSLex_Else,            3,    kSPrs_If,    kSLex_Context,    kSLex_SemiColon,
  2042.         10,    kSPrs_Else,            3,    kSPrs_If,    kSLex_Context,    kSLex_SemiColon,
  2043.          1,    kSLex_LParen,        2,    kSPrs_If,    kSLex_Context,
  2044.          0,    kSLex_If,            1,    kSPrs_If,
  2045.         15,    -1,                    4,    kSPrs_If,    kSLex_Context,    kSLex_Context,    kSLex_RCurly,
  2046.          7,    -1,                    3,    kSPrs_If,    kSLex_Context,    kSLex_RParen,
  2047.         11,    -1,                    3,    kSPrs_If,    kSLex_Context,    kSLex_SemiColon,
  2048.         
  2049.         -1, -1,                    0
  2050.         //ƒ+
  2051.         };
  2052.  
  2053.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  2054.     DEBUGPARSER(If, anIndex);
  2055.  
  2056.     switch (anIndex)
  2057.         {
  2058.     case  0:    //    ® • "if"                    -> ® kSLex_Context •
  2059.         aFormat->OpenContext();
  2060.         DEBUGSETCONTEXT(setExprContext)
  2061.         setExprContext(aFormat);
  2062.         aFormat->SetGlue(gFS_if0);
  2063.         aFormat->Display(aToken);
  2064.         aParser->Shift(&gContext);
  2065.         break;
  2066.         
  2067.     case  1:    //    ® kSLex_Context • "("        -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2068.         aFormat->OpenContext();
  2069.         aFormat->SetGlue(gFS_if1);
  2070.         aFormat->Display(aToken);
  2071.         aParser->Shift(&gContext);
  2072.         aParser->Shift(aToken);
  2073.         aParser->Shift(&gPrsExpr);
  2074.         break;
  2075.         
  2076.     case  2:    //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr
  2077.         aFormat->Comma();
  2078.         aFormat->Display(aToken);
  2079.         break;
  2080.         
  2081.     case  3:    //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr •  ")"    -> ® kSLex_Context ")" •
  2082.         aFormat->SetGlue(gFS_if2);
  2083.         aFormat->Display(aToken);
  2084.         aFormat->CloseContext();
  2085.         aParser->Drop(3);
  2086.         aParser->Shift(&gLexRParen);
  2087.         break;
  2088.         
  2089.     case  4:    //    ® kSLex_Context ")" • "{"                                -> ® kSLex_Context kSLex_Context "{" kSPrs_StmtList •
  2090.         aFormat->OpenContext();
  2091.         aFormat->SetGlue(gFS_if4);
  2092.         aFormat->Display(aToken);
  2093.         aParser->TopItem(&gContext);
  2094.         aParser->Shift(aToken);
  2095.         aParser->Shift(&gPrsStmtList);
  2096.         break;
  2097.         
  2098.     case  5:    //    ® kSLex_Context ")" • ";"            -> ® kSLex_Context ";" •
  2099.         aFormat->SetGlue(gFS_if3);
  2100.         aFormat->Display(aToken);
  2101.         aFormat->RestoreIndent();
  2102.         aParser->TopItem(&gLexSemiColon);
  2103.         break;
  2104.         
  2105.     case  6:    //    ® kSLex_Context ")" kSLex_Context • kSPrs_Stmt    -> ® kSLex_Context ";" •
  2106.         aFormat->CloseContext();
  2107.         aParser->Drop(2);
  2108.         aParser->Shift(&gLexSemiColon);
  2109.         break;
  2110.         
  2111.     case  7:    //    ® kSLex_Context ")" • ???            -> ® kSLex_Context ")" kSLex_Context kSPrs_Stmt • ???
  2112.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  2113.             {
  2114.             aParser->Shift(&gPrsNewLine);
  2115.             return (true);
  2116.             }
  2117.         if (aToken->IsSeparator())
  2118.             {
  2119.             aFormat->Display(aToken);
  2120.             return (true);
  2121.             }
  2122.         aFormat->OpenContext();
  2123.         aFormat->SetGlue(gFS_if7);
  2124.         aParser->Shift(&gContext);
  2125.         aParser->Shift(&gPrsStmt);
  2126.         aParser->Parse(aToken);
  2127.         break;
  2128.         
  2129.     case  8:    //    ® kSLex_Context kSLex_Context "{" kSPrs_StmtList • "}"    -> ® kSLex_Context kSLex_Context "}" •
  2130.         aParser->Drop(2);
  2131.         aParser->Shift(aToken);
  2132.         break;
  2133.         
  2134.     case  9:    //    ® kSLex_Context ";" • "else"                -> ® kSLex_Context ";" kSPrs_Else • "else"
  2135.         aParser->Shift(&gPrsElse);
  2136.         aParser->Parse(aToken);
  2137.         break;
  2138.         
  2139.     case 10:    //    ® kSLex_Context ";" • kSPrs_Else            -> • kSPrs_Stmt
  2140.         aFormat->CloseContext();
  2141.         aParser->Reduce(&gPrsStmt, 3);
  2142.         break;
  2143.         
  2144.     case 11:    //    ® kSLex_Context ";" • ???                    -> • kSPrs_Stmt ???
  2145.         // Aug 20, 1991
  2146.         // If there is a comment following (which has IsSeparator() true),
  2147.         // then the comment will cause the current context to be closed.
  2148.         // This means that a statement of the form:
  2149.         //        if (…)
  2150.         //            …
  2151.         //            // …comment…
  2152.         //        else
  2153.         //            …
  2154.         // will become a syntax error (or mis-format).  But life's tough
  2155.         // because the most common form for this pairing is for a statement
  2156.         // sequence like:
  2157.         //        if (…)
  2158.         //            …
  2159.         //        // comment for the code following
  2160.         //        …
  2161.         // which would otherwise have the comment indented more than it
  2162.         // should be.  This is a "shift-reduce" conflict, and the conflict
  2163.         // is now being resolved by doing a reduce instead of a shift
  2164.         if (aToken->Type() != kSLex_Comment && aToken->IsSeparator())
  2165.             {
  2166.             aFormat->Display(aToken);
  2167.             return (true);
  2168.             }
  2169.         aFormat->CloseContext();
  2170.         aParser->Reduce(&gPrsStmt, 3);
  2171.         aParser->Parse(aToken);
  2172.         break;
  2173.  
  2174.     case 12:    //    ® kSLex_Context ")" kSLex_Context kSPrs_Stmt • "else"    -> ® kSLex_Context ")" • kSPrs_Stmt "else"
  2175.         aFormat->CloseContext();
  2176.         aParser->Drop(2);
  2177.         Accept(&gPrsStmt, aParser);
  2178.         return (Accept(aToken, aParser));
  2179.  
  2180.     case 13:    //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • "{"    -> ® kSLex_Context ")" • "{"
  2181.         aFormat->CloseContext();
  2182.         aParser->Drop(3);
  2183.         aParser->Shift(&gLexRParen);
  2184.         return (Accept(aToken, aParser));
  2185.         
  2186.     case 14:    //    ® kSLex_Context kSLex_Context "}" • "else"    -> ® kSLex_Context ";" kSPrs_Else • "else"
  2187.         aFormat->SetGlue(gFS_if6);
  2188.         aFormat->Display(aParser->TopItem());
  2189.         aFormat->CloseContext();
  2190.         aParser->Drop(2);
  2191.         aParser->Shift(&gLexSemiColon);
  2192.         aParser->Shift(&gPrsElse);
  2193.         aParser->Parse(aToken);
  2194.         break;
  2195.         
  2196.     case 15:    //    ® kSLex_Context kSLex_Context "}" • ???        -> ® kSLex_Context ";" • ???
  2197.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  2198.             {
  2199.             aParser->Shift(&gPrsNewLine);
  2200.             return (true);
  2201.             }
  2202.         aFormat->SetGlue(gFS_if5);
  2203.         aFormat->Display(aParser->TopItem());
  2204.         aFormat->CloseContext();
  2205.         aParser->Drop(2);
  2206.         aParser->Shift(&gLexSemiColon);
  2207.         return (Accept(aToken, aParser));
  2208.  
  2209.     default:
  2210.         if (aToken->IsSeparator())
  2211.             {
  2212.             aFormat->Display(aToken);
  2213.             return (true);
  2214.             }
  2215.         return (false);
  2216.         }
  2217.         
  2218.     return (true);
  2219.     }
  2220.  
  2221.  
  2222. /*µ kSPrs_Else    ( 6)
  2223. **    ( 0)    ® • "else"                            -> ® kSLex_Context "else" •
  2224. **    ( 1)    ® kSLex_Context "else" • "if"        -> ® kSLex_Context "if" kSPrs_If • "if"
  2225. **    ( 6)    ® kSLex_Context "if" • kSPrs_Stmt    -> • kSPrs_Else
  2226. **        The "else" is not immediately displayed.  It is deferred until the
  2227. **        "if", "{" or ??? following it
  2228. **
  2229. **    ( 2)    ® kSLex_Context "else" • "{"                            -> ® kSLex_Context kSLex_Context "{" kSPrs_StmtList •
  2230. **    ( 5)    ® kSLex_Context kSLex_Context "{" kSPrs_StmtList • "}"    -> • kSPrs_Else
  2231. **
  2232. **    ( 3)    ® kSLex_Context "else" • ???                -> ® kSLex_Context kSLex_Context kSPrs_Stmt • ???
  2233. **    ( 4)    ® kSLex_Context kSLex_Context • kSPrs_Stmt    -> • kSPrs_Else
  2234. **        Envelop the statement in its own context
  2235. **
  2236. **    Handle the "else" clause of an if statement.  First, display "else" (0).
  2237. ** If the next token is an "if" (1), parse an if statement.  If the token is
  2238. ** a "{" (2), parse a statmentlist until the closing "}" (5).  Otherwise,
  2239. ** just do a single statement (3).  When a statement has been parsed (4),
  2240. ** reduce the else.
  2241. */
  2242. #pragma segment ParserActions
  2243. Boolean
  2244. PrsElse::Accept(Syntactic* aToken, Parser* aParser)
  2245.     {
  2246.     Formatting* aFormat = aParser->GetFormatting();
  2247.     static const short handles[] =
  2248.         {
  2249.         //ƒ-
  2250.          5, kSLex_RCurly,        5,    kSPrs_Else,    kSLex_Context,    kSLex_Context,    kSLex_LCurly,    kSPrs_StmtList,
  2251.          6, kSPrs_Stmt,            3,    kSPrs_Else,    kSLex_Context,    kSLex_If,
  2252.          1, kSLex_If,            3,    kSPrs_Else,    kSLex_Context,    kSLex_Else,
  2253.          2, kSLex_LCurly,        3,    kSPrs_Else,    kSLex_Context,    kSLex_Else,
  2254.          4, kSPrs_Stmt,            3,    kSPrs_Else,    kSLex_Context,    kSLex_Context,
  2255.          0, kSLex_Else,            1,    kSPrs_Else,
  2256.          3, -1,                    3,    kSPrs_Else,    kSLex_Context,    kSLex_Else,
  2257.  
  2258.         -1, -1,                    0
  2259.         //ƒ+
  2260.         };
  2261.  
  2262.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  2263.     DEBUGPARSER(Else, anIndex);
  2264.  
  2265.     switch (anIndex)
  2266.         {
  2267.     case  0:    //    ® • "else"                            -> ® kSLex_Context "else" •
  2268.         aFormat->OpenContext();
  2269.         DEBUGSETCONTEXT(setExprContext)
  2270.         setExprContext(aFormat);
  2271.         aParser->Shift(&gContext);
  2272.         aParser->Shift(aToken);
  2273.         break;
  2274.         
  2275.     case  1:    //    ® kSLex_Context "else" • "if"        -> ® kSLex_Context "if" kSPrs_If • "if"
  2276.         aFormat->SetGlue(gFS_else1);
  2277.         aFormat->Display(aParser->TopItem());
  2278.         aParser->TopItem(aToken);
  2279.         aParser->Shift(&gPrsIf);
  2280.         aParser->Parse(aToken);
  2281.         break;
  2282.         
  2283.     case  2:    //    ® kSLex_Context "else" • "{"                            -> ® kSLex_Context kSLex_Context "{" kSPrs_StmtList •
  2284.         aFormat->OpenContext();
  2285.         aFormat->SetGlue(gFS_else3);
  2286.         aFormat->Display(aParser->TopItem());
  2287.         aFormat->Display(aToken);
  2288.         aParser->TopItem(&gContext);
  2289.         aParser->Shift(aToken);
  2290.         aParser->Shift(&gPrsStmtList);
  2291.         break;
  2292.         
  2293.     case  3:    //    ® kSLex_Context "else" • ???                -> ® kSLex_Context kSLex_Context kSPrs_Stmt • ???
  2294.         // Explicitly disallow "else /*…*/ if", which is why there is no
  2295.         // check for IsSeparator().  Otherwise, the comment would migrate
  2296.         // before the "else"
  2297.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  2298.             {
  2299.             aParser->Shift(&gPrsNewLineIf);
  2300.             return (true);
  2301.             }
  2302.         aFormat->OpenContext();
  2303.         aFormat->SetGlue(gFS_else4);
  2304.         aFormat->Display(aParser->TopItem());
  2305.         aParser->TopItem(&gContext);
  2306.         aParser->Shift(&gPrsStmt);
  2307.         aParser->Parse(aToken);
  2308.         break;
  2309.         
  2310.     case  4:    //    ® kSLex_Context kSLex_Context • kSPrs_Stmt    -> • kSPrs_Else
  2311.         aFormat->CloseContext();
  2312.         aFormat->CloseContext();
  2313.         aParser->Reduce(&gPrsElse, 3);
  2314.         break;
  2315.  
  2316.     case  5:    //    ® kSLex_Context kSLex_Context "{" kSPrs_StmtList • "}"    -> • kSPrs_Else
  2317.         aFormat->SetGlue(gFS_else6);
  2318.         aFormat->Display(aToken);
  2319.         aFormat->CloseContext();
  2320.         aFormat->CloseContext();
  2321.         aParser->Reduce(&gPrsElse, 5);
  2322.         break;
  2323.  
  2324.     case  6:    //    ® kSLex_Context "if" • kSPrs_Stmt    -> • kSPrs_Else
  2325.         aFormat->CloseContext();
  2326.         aParser->Reduce(&gPrsElse, 3);
  2327.         break;
  2328.  
  2329.     case  7:    //    ® kSLex_Context "else" • \n            -> ® kSLex_Context "else" •
  2330.         break;
  2331.  
  2332.     default:
  2333.         if (aToken->IsSeparator())
  2334.             {
  2335.             aFormat->Display(aToken);
  2336.             return (true);
  2337.             }
  2338.         return (false);
  2339.         }
  2340.         
  2341.     return (true);
  2342.     }
  2343.  
  2344.  
  2345. /*µ kSPrs_For    (10)
  2346. **    ( 0)    ® • "for"                    -> ® kSLex_Context •
  2347. **    ( 1)    ® kSLex_Context • "("        -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2348. **    ( 2)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ";"            -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2349. **    ( 3)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ","            -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2350. **    ( 4)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ")"            -> ® kSLex_Context ")" •
  2351. **    ( 9)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • kSPrs_Decl    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2352. **
  2353. **    ( 5)    ® kSLex_Context ")" • "{"                    -> ® kSLex_Context "{" kSPrs_StmtList •
  2354. **    (10)    ® kSLex_Context ")" • ";"                    -> • kSPrs_Stmt
  2355. **    ( 6)    ® kSLex_Context ")" • ???                    -> ® kSLex_Context kSPrs_Stmt • ???
  2356. **
  2357. **    ( 7)    ® kSLex_Context "{" kSPrs_StmtList • "}"    -> • kSPrs_Stmt
  2358. **
  2359. **    ( 8)    ® kSLex_Context • kSPrs_Stmt                -> • kSPrs_Stmt
  2360. **
  2361. **    Recognize the "for" in (0) and then the "(" in (1).  Parse the
  2362. ** expression list, handling the ";" (2) and "," (3) until the closing
  2363. ** ") in (4).  Also handle initialization declarations (9) which consume
  2364. ** the ";".  If the token following the is a "{" (5) parse a statement
  2365. ** list until the closing "} (7).  Otherwise parse a single statment (8).
  2366. */
  2367. #pragma segment ParserActions
  2368. Boolean
  2369. PrsFor::Accept(Syntactic* aToken, Parser* aParser)
  2370.     {
  2371.     Formatting* aFormat = aParser->GetFormatting();
  2372.     static const short handles[] =
  2373.         {
  2374.         //ƒ-
  2375.          2, kSLex_SemiColon,    5,    kSPrs_For,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2376.          3, kSLex_Comma,        5,    kSPrs_For,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2377.          4, kSLex_RParen,        5,    kSPrs_For,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2378.          9, kSPrs_Decl,            5,    kSPrs_For,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2379.          7,    kSLex_RCurly,        4,    kSPrs_For,    kSLex_Context,    kSLex_LCurly,    kSPrs_StmtList,
  2380.          5,    kSLex_LCurly,        3,    kSPrs_For,    kSLex_Context,    kSLex_RParen,
  2381.         10,    kSLex_SemiColon,    3,    kSPrs_For,    kSLex_Context,    kSLex_RParen,
  2382.          1, kSLex_LParen,        2,    kSPrs_For,    kSLex_Context,
  2383.          8, kSPrs_Stmt,            2,    kSPrs_For,    kSLex_Context,
  2384.          0,    kSLex_For,            1,    kSPrs_For,
  2385.          6,    -1,                    3,    kSPrs_For,    kSLex_Context,    kSLex_RParen,
  2386.          
  2387.         -1, -1,                    0
  2388.         //ƒ+
  2389.         };
  2390.  
  2391.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  2392.     DEBUGPARSER(For, anIndex);
  2393.  
  2394.     switch (anIndex)
  2395.         {
  2396.     case  0:    //    ® • "for"                    -> ® kSLex_Context •
  2397.         aFormat->OpenContext();
  2398.         DEBUGSETCONTEXT(setExprContext)
  2399.         setExprContext(aFormat);
  2400.         aFormat->SetGlue(gFS_for0);
  2401.         aFormat->Display(aToken);
  2402.         aParser->Shift(&gContext);
  2403.         break;
  2404.         
  2405.     case  1:    //    ® kSLex_Context • "("        -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2406.         aFormat->OpenContext();
  2407.         aFormat->SetGlue(gFS_for1);
  2408.         aFormat->Display(aToken);
  2409.         aParser->Shift(&gContext);
  2410.         aParser->Shift(aToken);
  2411.         aParser->Shift(&gPrsExpr);
  2412.         break;
  2413.         
  2414.     case  2:    //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ";"            -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2415.         aFormat->SetGlue(gFS_for3);
  2416.         aFormat->Display(aToken);
  2417.         break;
  2418.         
  2419.     case  9:    //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • kSPrs_Decl    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2420.         // Temporary hack: indicate that a new line has taken place.
  2421.         aFormat->SetGlue((FormatString)"!n s#");
  2422.         break;
  2423.         
  2424.     case  3:    //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ","            -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2425.         aFormat->Comma();
  2426.         aFormat->Display(aToken);
  2427.         break;
  2428.         
  2429.     case  4:    //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ")"            -> ® kSLex_Context ")" •
  2430.         aFormat->SetGlue(gFS_for4);
  2431.         aFormat->Display(aToken);
  2432.         aFormat->CloseContext();
  2433.         aParser->Drop(3);
  2434.         aParser->Shift(aToken);
  2435.         break;
  2436.         
  2437.     case  5:    //    ® kSLex_Context ")" • "{"                    -> ® kSLex_Context "{" kSPrs_StmtList •
  2438.         aFormat->SetGlue(gFS_for5);
  2439.         aFormat->Display(aToken);
  2440.         aParser->TopItem(aToken);
  2441.         aParser->Shift(&gPrsStmtList);
  2442.         break;
  2443.  
  2444.     case 10:    //    ® kSLex_Context ")" • ";"                    -> • kSPrs_Stmt
  2445.         aFormat->SetGlue(gFS_for6);
  2446.         aFormat->Display(aToken);
  2447.         aFormat->CloseContext();
  2448.         aParser->Reduce(&gPrsStmt, 3);
  2449.         break;
  2450.  
  2451.     case  6:    //    ® kSLex_Context ")" • ???                    -> ® kSLex_Context kSPrs_Stmt • ???
  2452.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  2453.             {
  2454.             aParser->Shift(&gPrsNewLine);
  2455.             return (true);
  2456.             }
  2457.         if (aToken->IsSeparator())
  2458.             {
  2459.             aFormat->Display(aToken);
  2460.             return (true);
  2461.             }
  2462.         aFormat->SetGlue(gFS_for7);
  2463.         aParser->TopItem(&gPrsStmt);
  2464.         aParser->Parse(aToken);
  2465.         break;
  2466.         
  2467.     case  7:    //    ® kSLex_Context "{" kSPrs_StmtList • "}"    -> • kSPrs_Stmt
  2468.         aFormat->SetGlue(gFS_for8);
  2469.         aFormat->Display(aToken);
  2470.         aFormat->CloseContext();
  2471.         aParser->Reduce(&gPrsStmt, 4);
  2472.         break;
  2473.         
  2474.     case  8:    //    ® kSLex_Context • kSPrs_Stmt                -> • kSPrs_Stmt
  2475.         aFormat->CloseContext();
  2476.         aParser->Reduce(&gPrsStmt, 2);
  2477.         break;
  2478.  
  2479.     default:
  2480.         if (aToken->IsSeparator())
  2481.             {
  2482.             aFormat->Display(aToken);
  2483.             return (true);
  2484.             }
  2485.         return (false);
  2486.         }
  2487.         
  2488.     return (true);
  2489.     }
  2490.  
  2491.  
  2492. /*µ kSPrs_Struct    (18)
  2493. **    ( 0)    ® • "struct"                        -> ® kSLex_Context •
  2494. **        Recognize the word "struct" and emit it.  The word is not emitted until
  2495. **        a later time.
  2496. **
  2497. **    ( 1)    ® kSLex_Context • "{"                        -> ® kSLex_Context "{" kSPrs_DeclList •
  2498. **    (16)    ® kSLex_Context "{" kSPrs_DeclList • ","    -> ® kSLex_Context "{" kSPrs_DeclList •
  2499. **    ( 2)    ® kSLex_Context "{" kSPrs_DeclList • "}"    -> ® kSLex_Context "{" "}" •
  2500. **    (17)    ® kSLex_Context "{" "}" • ";"                -> • kSPrs_Decl
  2501. **    (18)    ® kSLex_Context "{" "}" • ???                -> • kSPrs_DeclType ???
  2502. **        When the opening curly is found, enter the body of the struct.  Then
  2503. **        body is a declaration list.  When the closing curly is found, emit the
  2504. **        kSPrs_DeclType.  A comma in the middle of the list is usually because
  2505. **        the struct is an enum
  2506. **
  2507. **    ( 3)    ? • kSLex_Public                    -> ? kSLex_Public •
  2508. **    ( 4)    ? KSLex_Public • ":"                -> ? •
  2509. **    ( 5)    ? KSLex_Public • ???                -> ? • ???
  2510. **        Within the body of a struct the "public" keywords are allowed.  They
  2511. **        are followed by ":" and have no other effect.  We delay the display
  2512. **        of the word public until we know that this is a C++ public declaration
  2513. **        and not the name of a field (for example).
  2514. **
  2515. **    ( 6)    ® kSLex_Context • kSLex_ParsedId        -> ® kSLex_Context kSLex_ParsedId •
  2516. **    ( 7)    ® kSLex_Context kSLex_ParsedId • "{"    -> ® kSLex_Context "{" kSPrs_DeclList •
  2517. **    ( 8)    ® kSLex_Context kSLex_ParsedId • ":"    -> ® kSLex_Context kSLex_ParsedId ":" •
  2518. **    ( 9)    ® kSLex_Context kSLex_ParsedId • ???    -> • kSPrs_DeclType ???
  2519. **        A "struct" can also be followed by a name and optional inheritance
  2520. **        information.  This state is denoted by "® kSLex_ParsedId •".  When
  2521. **        followed by "{", it devolves into the unnamed struct declaration list
  2522. **        mentioned above.  When followed by a ":", inheritance information must
  2523. **        be parsed ("® kSLex_ParsedId ":" •").  Otherwise, reduce it to a
  2524. **        kSPrs_DeclType and pass the extra token upstairs.
  2525. **
  2526. **    (10)    ® kSLex_Context kSLex_ParsedId ":" • kSLex_ParsedId    -> ® kSLex_Context kSLex_ParsedId ":" •
  2527. **    (11)    ® kSLex_Context kSLex_ParsedId ":" • kSLex_Public    -> ® kSLex_Context kSLex_ParsedId ":" •
  2528. **    (12)    ® kSLex_Context kSLex_ParsedId ":" • kSLex_Decl        -> ® kSLex_Context kSLex_ParsedId ":" •
  2529. **    (13)    ® kSLex_Context kSLex_ParsedId ":" • ","            -> ® kSLex_Context kSLex_ParsedId ":" •
  2530. **    (14)    ® kSLex_Context kSLex_ParsedId ":" • ???            -> ® kSLex_Context kSLex_ParsedId • ???
  2531. **        Inheritance information is a bunch of comma separated "public", types
  2532. **        and identifiers.  Anything else (such as "{") reduces to a named
  2533. **        struct ("® kSLex_ParsedId •") and is processed that way.
  2534. **
  2535. **    (15)    ® kSLex_Context • ???                    -> • kSPrs_DeclType ???
  2536. **        If the word "struct" is followed by anything unexpected, reduce it
  2537. **        to a DeclType and pass the token following it upstairs.
  2538. */
  2539. #pragma segment ParserActions
  2540. Boolean
  2541. PrsStruct::Accept(Syntactic* aToken, Parser* aParser)
  2542.     {
  2543.     Formatting* aFormat = aParser->GetFormatting();
  2544.     static const short handles[] =
  2545.         {
  2546.         //ƒ-
  2547.          2, kSLex_RCurly,        4,    kSPrs_Struct,    kSLex_Context,    kSLex_LCurly,    kSPrs_DeclList,
  2548.         16, kSLex_Comma,        4,    kSPrs_Struct,    kSLex_Context,    kSLex_LCurly,    kSPrs_DeclList,
  2549.         17, kSLex_SemiColon,    4,    kSPrs_Struct,    kSLex_Context,    kSLex_LCurly,    kSLex_RCurly,
  2550.         10,    kSLex_ParsedId,        4,    kSPrs_Struct,    kSLex_Context,    kSLex_ParsedId,    kSLex_Colon,
  2551.         11,    kSLex_Public,        4,    kSPrs_Struct,    kSLex_Context,    kSLex_ParsedId,    kSLex_Colon,
  2552.         12,    kSLex_Decl,            4,    kSPrs_Struct,    kSLex_Context,    kSLex_ParsedId,    kSLex_Colon,
  2553.         13,    kSLex_Comma,        4,    kSPrs_Struct,    kSLex_Context,    kSLex_ParsedId,    kSLex_Colon,
  2554.          7, kSLex_LCurly,        3,    kSPrs_Struct,    kSLex_Context,    kSLex_ParsedId,
  2555.          8, kSLex_Colon,        3,    kSPrs_Struct,    kSLex_Context,    kSLex_ParsedId,
  2556.          1, kSLex_LCurly,        2,    kSPrs_Struct,    kSLex_Context,
  2557.          6,    kSLex_ParsedId,        2,    kSPrs_Struct,    kSLex_Context,
  2558.          0,    kSLex_Struct,        1,    kSPrs_Struct,
  2559.          4, kSLex_Colon,        1,    kSLex_Public,
  2560.          3, kSLex_Public,        0,
  2561.         18, -1,                    4,    kSPrs_Struct,    kSLex_Context,    kSLex_LCurly,    kSLex_RCurly,
  2562.         14,    -1,                    4,    kSPrs_Struct,    kSLex_Context,    kSLex_ParsedId,    kSLex_Colon,
  2563.          9, -1,                    3,    kSPrs_Struct,    kSLex_Context,    kSLex_ParsedId,
  2564.         15, -1,                    2,    kSPrs_Struct,    kSLex_Context,
  2565.          5, -1,                    1,    kSLex_Public,
  2566.  
  2567.         -1, -1,                    0
  2568.         //ƒ+
  2569.         };
  2570.  
  2571.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  2572.     DEBUGPARSER(Struct, anIndex);
  2573.  
  2574.     switch (anIndex)
  2575.         {
  2576.     case  0:    //    ® • "struct"                        -> ® kSLex_Context •
  2577.         aFormat->OpenContext();
  2578.         DEBUGSETCONTEXT(setDeclContext)
  2579.         setDeclContext(aFormat);
  2580.         aFormat->SetGlue(gFS_struct0);
  2581.         aFormat->Display(aToken);
  2582.         aParser->Shift(&gContext);
  2583.         break;
  2584.         
  2585.     case  1:    //    ® kSLex_Context • "{"                        -> ® kSLex_Context "{" kSPrs_DeclList •
  2586.         aFormat->SetGlue(gFS_struct3);
  2587.         aFormat->Display(aToken);
  2588.         aParser->Shift(aToken);
  2589.         aParser->Shift(&gPrsDeclList);
  2590.         break;
  2591.  
  2592.     case  2:    //    ® kSLex_Context "{" kSPrs_DeclList • "}"    -> ® kSLex_Context "{" "}" •
  2593.         aFormat->SetGlue(gFS_struct6);
  2594.         aFormat->Display(aToken);
  2595.         aParser->TopItem(aToken);
  2596.         break;
  2597.  
  2598.     case  3:    //    ? • kSLex_Public                    -> ? kSLex_Public •
  2599.         aParser->Shift(aToken);
  2600.         break;
  2601.  
  2602.     case  4:    //    ? KSLex_Public • ":"                -> ? •
  2603.         aFormat->SetGlue(gFS_struct5);
  2604.         aFormat->Display(aParser->TopItem());
  2605.         aFormat->Display(aToken);
  2606.         aParser->Drop(1);
  2607.         break;
  2608.         
  2609.     case  5:    //    ? KSLex_Public • ???                -> ? • ???
  2610.         if (aToken->IsSeparator())
  2611.             {
  2612.             aFormat->Display(aToken);
  2613.             return (true);
  2614.             }
  2615.         aParser->Reduce(new PrsAsId(aParser->TopItem()), 1);
  2616.         return (aParser->Parse(aToken));
  2617.  
  2618.     case  6:    //    ® kSLex_Context • kSLex_ParsedId        -> ® kSLex_Context kSLex_ParsedId •
  2619.         aFormat->Name();
  2620.         aFormat->Display(aToken);
  2621.         aParser->Shift(aToken);
  2622.         break;
  2623.  
  2624.     case  7:    //    ® kSLex_Context kSLex_ParsedId • "{"    -> ® kSLex_Context "{" kSPrs_DeclList •
  2625.         aFormat->RestoreIndent();
  2626.         aFormat->SetGlue(gFS_struct3);
  2627.         aFormat->Display(aToken);
  2628.         aParser->TopItem(aToken);
  2629.         aParser->Shift(&gPrsDeclList);
  2630.         break;
  2631.  
  2632.     case  8:    //    ® kSLex_Context kSLex_ParsedId • ":"    -> ® kSLex_Context kSLex_ParsedId ":" •
  2633.         aFormat->SetGlue(gFS_struct1);
  2634.         aFormat->Display(aToken);
  2635.         aParser->Shift(aToken);
  2636.         break;
  2637.  
  2638.     case  9:    //    ® kSLex_Context kSLex_ParsedId • ???    -> • kSPrs_DeclType ???
  2639.         if (aToken->IsSeparator())
  2640.             {
  2641.             aFormat->Display(aToken);
  2642.             return (true);
  2643.             }
  2644.         aFormat->CloseContext();
  2645.         aParser->Reduce(&gPrsDeclType, 3);
  2646.         return (aParser->Parse(aToken));
  2647.  
  2648.     case 10:    //    ® kSLex_Context kSLex_ParsedId ":" • kSLex_ParsedId    -> ® kSLex_Context kSLex_ParsedId ":" •
  2649.     case 11:    //    ® kSLex_Context kSLex_ParsedId ":" • kSLex_Public    -> ® kSLex_Context kSLex_ParsedId ":" •
  2650.     case 12:    //    ® kSLex_Context kSLex_ParsedId ":" • kSLex_Decl        -> ® kSLex_Context kSLex_ParsedId ":" •
  2651.         aFormat->Name();
  2652.         aFormat->Display(aToken);
  2653.         break;
  2654.  
  2655.     case 13:    //    ® kSLex_Context kSLex_ParsedId ":" • ","            -> ® kSLex_Context kSLex_ParsedId ":" •
  2656.         aFormat->SetGlue(gFS_struct2);
  2657.         aFormat->Display(aToken);
  2658.         break;
  2659.  
  2660.     case 14:    //    ® kSLex_Context kSLex_ParsedId ":" • ???            -> ® kSLex_Context kSLex_ParsedId • ???
  2661.         if (aToken->IsSeparator())
  2662.             {
  2663.             aFormat->Display(aToken);
  2664.             return (true);
  2665.             }
  2666.         aFormat->RestoreIndent();
  2667.         aParser->Drop(1);
  2668.         return (Accept(aToken, aParser));
  2669.  
  2670.     case 15:    //    ® kSLex_Context • ???                    -> • kSPrs_DeclType ???
  2671.         if (aToken->IsSeparator())
  2672.             {
  2673.             aFormat->Display(aToken);
  2674.             return (true);
  2675.             }
  2676.         aFormat->CloseContext();
  2677.         aParser->Reduce(&gPrsDeclType, 2);
  2678.         return (aParser->Parse(aToken));
  2679.  
  2680.     case 16:    //    ® kSLex_Context "{" kSPrs_DeclList • ","    -> ® kSLex_Context "{" kSPrs_DeclList •
  2681.         aFormat->Comma();
  2682.         aFormat->Display(aToken);
  2683.         break;
  2684.  
  2685.     case 17:    //    ® kSLex_Context "{" "}" • ";"                -> • kSPrs_Decl
  2686.         aFormat->SetGlue(gFS_struct7);
  2687.         aFormat->Display(aToken);
  2688.         aFormat->CloseContext();
  2689.         aParser->Reduce(&gPrsDecl, 4);
  2690.         break;
  2691.  
  2692.     case 18:    //    ® kSLex_Context "{" "}" • ???                -> • kSPrs_DeclType ???
  2693.         if (aToken->IsSeparator())
  2694.             {
  2695.             aFormat->Display(aToken);
  2696.             return (true);
  2697.             }
  2698.         aFormat->CloseContext();
  2699.         aParser->Reduce(&gPrsDeclType, 4);
  2700.         return (aParser->Parse(aToken));
  2701.  
  2702.     default:
  2703.         if (aToken->IsSeparator())
  2704.             {
  2705.             aFormat->Display(aToken);
  2706.             return (true);
  2707.             }
  2708.         return (false);
  2709.         }
  2710.         
  2711.     return (true);
  2712.     }
  2713.  
  2714.  
  2715. /*µ kSPrs_Switch    ( 8)
  2716. **    ( 0)    ® • "switch"            -> ® kSLex_Context •
  2717. **    ( 1)    ® kSLex_Context • "("    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2718. **    ( 2)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2719. **    ( 3)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_Context ")" •
  2720. **
  2721. **    ( 4)    ® kSLex_Context ")" • "{"                    -> ® kSLex_Context "{" kSPrs_StmtList •
  2722. **    ( 5)    ® kSLex_Context "{" kSPrs_StmtList • "}"    -> • kSPrs_Stmt
  2723. **
  2724. **    ( 6)    ? • "case"                         -> ? "case" kSPrs_Expr •
  2725. **    ( 7)    ? • "default"                    -> ? "case" kSPrs_Expr •
  2726. **    ( 8)    ? "case" kSPrs_Expr • ":"        -> ? •
  2727. **
  2728. **    The "switch" is followed by a "(<expr>)", (0, 1, 2).  The body of the
  2729. ** switch is bracketed by "{..}".  The opening is recognized by (3).  At
  2730. ** that point, a statement list is recognized (4..6), with the addition of
  2731. ** "case" (4) and "default" (5).  Parsing of the statement list does not
  2732. ** resume until the closing ":" for the case/default has been recognized
  2733. ** done by (7) and (8).  Note that states (4) and (5) are not in the list
  2734. ** of handles as Parser::FindHandle() does not have a syntax for arbitrary
  2735. ** right hand side and it is not known what kSPrs_StmtList might have on the
  2736. ** parse stack at the time.
  2737. */
  2738. #pragma segment ParserActions
  2739. Boolean
  2740. PrsSwitch::Accept(Syntactic* aToken, Parser* aParser)
  2741.     {
  2742.     Formatting* aFormat = aParser->GetFormatting();
  2743.     static const short handles[] =
  2744.         {
  2745.         //ƒ-
  2746.          2,    kSLex_Comma,        5,    kSPrs_Switch,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2747.          3,    kSLex_RParen,        5,    kSPrs_Switch,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2748.          5, kSLex_RCurly,        4,    kSPrs_Switch,    kSLex_Context,    kSLex_LCurly,    kSPrs_StmtList,
  2749.          4,    kSLex_LCurly,        3,    kSPrs_Switch,    kSLex_Context,    kSLex_RParen,
  2750.          1,    kSLex_LParen,        2,    kSPrs_Switch,    kSLex_Context,
  2751.          8, kSLex_Colon,        2,    kSLex_Case,        kSPrs_Expr,
  2752.          0,    kSLex_Switch,         1,    kSPrs_Switch,
  2753.          6, kSLex_Case,            0,
  2754.          7, kSLex_Default,        0,
  2755.  
  2756.         -1, -1,                    0
  2757.         //ƒ+
  2758.         };
  2759.  
  2760.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  2761.     DEBUGPARSER(Switch, anIndex);
  2762.  
  2763.     switch (anIndex)
  2764.         {
  2765.     case 0:        //    ® • "switch"            -> ® kSLex_Context •
  2766.         aFormat->OpenContext();
  2767.         DEBUGSETCONTEXT(setExprContext)
  2768.         setExprContext(aFormat);
  2769.         aFormat->SetGlue(gFS_switch0);
  2770.         aFormat->Display(aToken);
  2771.         aParser->Shift(&gContext);
  2772.         break;
  2773.         
  2774.     case 1:        //    ® kSLex_Context • "("    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2775.         aFormat->OpenContext();
  2776.         aFormat->SetGlue(gFS_switch1);
  2777.         aFormat->Display(aToken);
  2778.         aParser->Shift(&gContext);
  2779.         aParser->Shift(aToken);
  2780.         aParser->Shift(&gPrsExpr);
  2781.         break;
  2782.  
  2783.     case 2:        //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2784.         aFormat->Comma();
  2785.         aFormat->Display(aToken);
  2786.         break;
  2787.         
  2788.     case 3:        //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_Context ")" •
  2789.         aFormat->RParen();
  2790.         aFormat->Display(aToken);
  2791.         aFormat->CloseContext();
  2792.         aParser->Drop(3);
  2793.         aParser->Shift(aToken);
  2794.         break;
  2795.         
  2796.     case 4:        //    ® kSLex_Context ")" • "{"                    -> ® kSLex_Context "{" kSPrs_StmtList •
  2797.         aFormat->SetGlue(gFS_switch2);
  2798.         aFormat->Display(aToken);
  2799.         aParser->TopItem(aToken);
  2800.         aParser->Shift(&gPrsStmtList);
  2801.         break;
  2802.         
  2803.     case 5:        //    ® kSLex_Context "{" kSPrs_StmtList • "}"    -> • kSPrs_Stmt
  2804.         aFormat->SetGlue(gFS_switch7);
  2805.         aFormat->Display(aToken);
  2806.         aFormat->CloseContext();
  2807.         aParser->Reduce(&gPrsStmt, 4);
  2808.         break;
  2809.  
  2810.     case 6:        //    ? • "case"                         -> ? "case" kSPrs_Expr •
  2811.     case 7:        //    ? • "default"                    -> ? "case" kSPrs_Expr •
  2812.         aFormat->SetGlue(aToken->Type() == kSLex_Case ? gFS_switch3 : gFS_switch4);
  2813.         aFormat->Display(aToken);
  2814.         aParser->Shift(&gLexCase);
  2815.         aParser->Shift(&gPrsExpr);
  2816.         break;
  2817.  
  2818.     case 8:        //    ? "case" kSPrs_Expr • ":"        -> ? •
  2819.         aFormat->SetGlue(gFS_switch5);
  2820.         aFormat->Display(aToken);
  2821.         aParser->Drop(2);
  2822.         break;
  2823.         
  2824.     default:
  2825.         if (aToken->IsSeparator())
  2826.             {
  2827.             aFormat->Display(aToken);
  2828.             return (true);
  2829.             }
  2830.         return (false);
  2831.         }
  2832.  
  2833.     return (true);
  2834.     }
  2835.  
  2836.  
  2837. /*µ kSPrs_While    ( 8)
  2838. **    ( 0)    ® • "while"                        -> ® kSLex_Context •
  2839. **    ( 2)    ® kSLex_Context • "("            -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2840. **    ( 8)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2841. **    ( 3)    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_Context ")" •
  2842. **
  2843. **    ( 4)    ® kSLex_Context ")" • "{"                    -> ® kSLex_Context "{" kSPrs_StmtList •
  2844. **    ( 7)    ® kSLex_Context "{" kSPrs_StmtList • "}"    -> • kSPrs_Stmt
  2845. **
  2846. **    ( 5)    ® kSLex_Context ")" • ";"        -> • kSPrs_Stmt
  2847. **
  2848. **    ( 6)    ® kSLex_Context ")" • ???        -> ® kSLex_Context kSPrs_Stmt • ???
  2849. **    ( 1)    ® kSLex_Context • kSPrs_Stmt    -> • kSPrs_Stmt
  2850. **
  2851. **
  2852. **    The "while" is followed by a "(...)", handled by (0, 2, 3) and then
  2853. ** a statement.  The statement can be a ";", handled by (5), a "{...}",
  2854. ** handled by (4, 7), or some other statement, handled by (6, 1)
  2855. */
  2856. #pragma segment ParserActions
  2857. Boolean
  2858. PrsWhile::Accept(Syntactic* aToken, Parser* aParser)
  2859.     {
  2860.     Formatting* aFormat = aParser->GetFormatting();
  2861.     static const short handles[] =
  2862.         {
  2863.         //ƒ-
  2864.          3,    kSLex_RParen,        5,    kSPrs_While,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2865.          8,    kSLex_Comma,        5,    kSPrs_While,    kSLex_Context,    kSLex_Context,    kSLex_LParen,    kSPrs_Expr,
  2866.          7,    kSLex_RCurly,        4,    kSPrs_While,    kSLex_Context,    kSLex_LCurly,    kSPrs_StmtList,
  2867.          4,    kSLex_LCurly,        3,    kSPrs_While,    kSLex_Context,    kSLex_RParen,
  2868.          5,    kSLex_SemiColon,    3,    kSPrs_While,    kSLex_Context,    kSLex_RParen,
  2869.          1,    kSPrs_Stmt,             2,    kSPrs_While,    kSLex_Context,
  2870.          2,    kSLex_LParen,        2,    kSPrs_While,    kSLex_Context,
  2871.          0,    kSLex_While,         1,    kSPrs_While,
  2872.          6,    -1,                    3,    kSPrs_While,    kSLex_Context,    kSLex_RParen,
  2873.  
  2874.         -1, -1,                    0
  2875.         //ƒ+
  2876.         };
  2877.  
  2878.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  2879.     DEBUGPARSER(While, anIndex);
  2880.  
  2881.     switch (anIndex)
  2882.         {
  2883.     case 0:        //    ® • "while"                        -> ® kSLex_Context •
  2884.         aFormat->OpenContext();
  2885.         DEBUGSETCONTEXT(setExprContext)
  2886.         setExprContext(aFormat);
  2887.         aFormat->SetGlue(gFS_while0);
  2888.         aFormat->Display(aToken);
  2889.         aParser->Shift(&gContext);
  2890.         break;
  2891.         
  2892.     case 1:        //    ® kSLex_Context • kSPrs_Stmt    -> • kSPrs_Stmt
  2893.         aFormat->CloseContext();
  2894.         aParser->Reduce(aToken, 2);
  2895.         break;
  2896.         
  2897.     case 2:        //    ® kSLex_Context • "("            -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2898.         aFormat->OpenContext();
  2899.         aFormat->SetGlue(gFS_while1);
  2900.         aFormat->Display(aToken);
  2901.         aParser->Shift(&gContext);
  2902.         aParser->Shift(aToken);
  2903.         aParser->Shift(&gPrsExpr);
  2904.         break;
  2905.  
  2906.     case 3:        //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_Context ")" •
  2907.         aFormat->SetGlue(gFS_while6);
  2908.         aFormat->Display(aToken);
  2909.         aFormat->CloseContext();
  2910.         aParser->Drop(3);
  2911.         aParser->Shift(aToken);
  2912.         break;
  2913.         
  2914.     case 8:        //    ® kSLex_Context kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_Context kSLex_Context "(" kSPrs_Expr •
  2915.         aFormat->Comma();
  2916.         aFormat->Display(aToken);
  2917.         break;
  2918.         
  2919.     case 4:        //    ® kSLex_Context ")" • "{"                    -> ® kSLex_Context "{" kSPrs_StmtList •
  2920.         aFormat->SetGlue(gFS_while2);
  2921.         aFormat->Display(aToken);
  2922.         aParser->TopItem(aToken);
  2923.         aParser->Shift(&gPrsStmtList);
  2924.         break;
  2925.         
  2926.     case 5:        //    ® kSLex_Context ")" • ";"        -> • kSPrs_Stmt
  2927.         aFormat->SetGlue(gFS_while3);
  2928.         aFormat->Display(aToken);
  2929.         aFormat->CloseContext();
  2930.         aParser->Reduce(&gPrsStmt, 3);
  2931.         break;
  2932.  
  2933.     case 6:        //    ® kSLex_Context ")" • ???        -> ® kSLex_Context kSPrs_Stmt • ???
  2934.         if (aToken->Type() == kSLex_NewLine && !aFormat->PassSourceNewLines())
  2935.             {
  2936.             aParser->Shift(&gPrsNewLine);
  2937.             return (true);
  2938.             }
  2939.         aFormat->SetGlue(gFS_while4);
  2940.         aParser->TopItem(&gPrsStmt);
  2941.         aParser->Parse(aToken);
  2942.         break;
  2943.             
  2944.     case 7:        //    ® kSLex_Context "{" kSPrs_StmtList • "}"    -> • kSPrs_Stmt
  2945.         aFormat->SetGlue(gFS_while5);
  2946.         aFormat->Display(aToken);
  2947.         aFormat->CloseContext();
  2948.         aParser->Reduce(&gPrsStmt, 4);
  2949.         break;
  2950.             
  2951.     default:
  2952.         if (aToken->IsSeparator())
  2953.             {
  2954.             aFormat->Display(aToken);
  2955.             return (true);
  2956.             }
  2957.         return (false);
  2958.         }
  2959.  
  2960.     return (true);
  2961.     }
  2962.  
  2963.  
  2964.  
  2965. /*µ kSPrs_Expr    (36)
  2966. **    ( 0)    ® • "("                                    -> ® kSLex_Context "(" kSPrs_Expr •
  2967. **    (34)    ? • "("                                    -> ? kSPrs_Expr • "("
  2968. **    ( 8)    ® kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_ParsedId •
  2969. **    ( 9)    ® kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_Context "(" kSPrs_Expr •
  2970. **        A "(" is ambiguous.  It can be a cast or the beginning of an expression.
  2971. **        consequently, wait for the next token, which can be a declaration
  2972. **        word, in which case we assume it's a cast, or a anything else, which
  2973. **        makes it an expression.
  2974. **
  2975. **    ( 1)    ® • "["                                    -> ® kSLex_Context "[" kSPrs_Expr •
  2976. **    (10)    ® kSLex_Context "[" kSPrs_Expr • "]"    -> ® kSLex_ParsedId •
  2977. **    (11)    ® kSLex_Context "[" kSPrs_Expr • ","    -> ® kSLex_Context "[" •
  2978. **        A bracketed expression might have commas in it.  Handle it.  Reduce
  2979. **        to the base state when the close brace comes.
  2980. **
  2981. **    ( 3)    ® • kSLex_Op                        -> ® kSLex_Op •
  2982. **    (12)    ® kSLex_Op • "("                    -> ® • "("
  2983. **    (26)    ® kSLex_Op • "["                    -> ® • "["
  2984. **    (13)    ® kSLex_Op • kSLex_Op                -> ® kSLex_Op •
  2985. **    (14)    ® kSLex_Op • kSLex_ParsedId            -> ® kSLex_ParsedId •
  2986. **    (15)    ® kSLex_Op • "struct"                -> ® kSPrs_Decl • "struct"
  2987. **    (16)    ® kSLex_Op • kSLex_Value            -> ® kSLex_ParsedId •
  2988. **    (17)    ® kSLex_Op • kSLex_Ellipsis            -> ® kSLex_ParsedId •
  2989. **    (18)    ® kSLex_Op • ???                    -> ® • ???
  2990. **
  2991. **    (32)    ® • "?"                                    -> ® kSLex_Context "?" kSPrs_Expr •
  2992. **    (28)    ® kSLex_Context "?" kSPrs_Expr • ":"    -> ® •
  2993. **    (31)    ® kSLex_Context "?" kSPrs_Expr • ","    -> ® kSLex_Context "?" kSPrs_Expr •
  2994. **        Conditional expressions can have commas in the true part.  Handle
  2995. **        them.
  2996. **
  2997. **    ( 2)    ® • "struct"                        -> ® kSPrs_Decl • "struct"
  2998. **    (35)    ® • kSLex_Decl                        -> ® kSPrs_Decl • kSLex_Decl
  2999. **    (33)    ® kSPrs_Decl • ???                    -> ® • ???
  3000. **        When a declarative entity returns, return to normal operation.
  3001. **
  3002. **    ( 4)    ® • kSLex_ParsedId                    -> ® kSLex_ParsedId •
  3003. **    ( 5)    ® • kSPrs_DeclType                    -> ® kSLex_ParsedId •
  3004. **    ( 6)    ® • kSLex_Value                        -> ® kSLex_ParsedId •
  3005. **    ( 7)    ® • kSLex_Ellipsis                    -> ® kSLex_ParsedId •
  3006. **    (27)    ® kSLex_ParsedId • "["                -> ® • "["
  3007. **    (20)    ® kSLex_ParsedId • kSLex_Op            -> ® kSLex_Op •
  3008. **    (21)    ® kSLex_ParsedId • kSLex_ParsedId    -> ® kSLex_ParsedId •
  3009. **    (22)    ® kSLex_ParsedId • "struct"            -> ® • "struct"
  3010. **    (23)    ® kSLex_ParsedId • kSLex_Value        -> ® kSLex_ParsedId •
  3011. **    (24)    ® kSLex_ParsedId • kSLex_Ellipsis    -> ® kSLex_ParsedId •
  3012. **
  3013. **    (19)    ® kSLex_ParsedId • "("                                -> ® kSLex_ParsedId kSLex_Context "(" kSPrs_Expr •
  3014. **    (29)    ® kSLex_ParsedId kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_ParsedId kSLex_Context "(" kSPrs_Expr •
  3015. **    (36)    ® kSLex_ParsedId kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_ParsedId •
  3016. **
  3017. **    (25)    ® kSLex_ParsedId • ???                -> ® • ???
  3018. **
  3019. **    An expression is a pile of symbols with balanced brackets.  Spaces are
  3020. ** inserted between id-like things, hence the kSLex_ParsedId entries saved on the
  3021. ** stack.  An expression never terminates: it remains on the stack consuming
  3022. ** valid tokens until someone else removes it.
  3023. */
  3024. #pragma segment ParserActions
  3025. Boolean
  3026. PrsExpr::Accept(Syntactic* aToken, Parser* aParser)
  3027.     {
  3028.     Formatting* aFormat = aParser->GetFormatting();
  3029.     static const short handles[] =
  3030.         {
  3031.         //ƒ-
  3032.         29, kSLex_Comma,        5,    kSPrs_Expr,    kSLex_ParsedId,        kSLex_Context,        kSLex_LParen,        kSPrs_Expr,
  3033.         36, kSLex_RParen,        5,    kSPrs_Expr,    kSLex_ParsedId,        kSLex_Context,        kSLex_LParen,        kSPrs_Expr,
  3034.          8, kSLex_RParen,        4,    kSPrs_Expr,    kSLex_Context,        kSLex_LParen,        kSPrs_Expr,
  3035.          9, kSLex_Comma,        4,    kSPrs_Expr,    kSLex_Context,        kSLex_LParen,        kSPrs_Expr,
  3036.         10, kSLex_RBrace,        4,    kSPrs_Expr,    kSLex_Context,        kSLex_LBrace,        kSPrs_Expr,
  3037.         11, kSLex_Comma,        4,    kSPrs_Expr,    kSLex_Context,        kSLex_LBrace,        kSPrs_Expr,
  3038.         28, kSLex_Colon,        4,    kSPrs_Expr,    kSLex_Context,        kSLex_OpQuestion,    kSPrs_Expr,
  3039.         31, kSLex_Comma,        4,    kSPrs_Expr,    kSLex_Context,        kSLex_OpQuestion,    kSPrs_Expr,
  3040.         12, kSLex_LParen,        2,    kSPrs_Expr,    kSLex_Op,
  3041.         26, kSLex_LBrace,        2,    kSPrs_Expr,    kSLex_Op,
  3042.         13, kSLex_Op,            2,    kSPrs_Expr,    kSLex_Op,
  3043.         14, kSLex_ParsedId,        2,    kSPrs_Expr,    kSLex_Op,
  3044.         15, kSLex_Struct,        2,    kSPrs_Expr,    kSLex_Op,
  3045.         16, kSLex_Value,        2,    kSPrs_Expr,    kSLex_Op,
  3046.         17, kSLex_Ellipsis,        2,    kSPrs_Expr,    kSLex_Op,
  3047.         19, kSLex_LParen,        2,    kSPrs_Expr,    kSLex_ParsedId,
  3048.         27, kSLex_LBrace,        2,    kSPrs_Expr,    kSLex_ParsedId,
  3049.         20, kSLex_Op,            2,    kSPrs_Expr,    kSLex_ParsedId,
  3050.         21, kSLex_ParsedId,        2,    kSPrs_Expr,    kSLex_ParsedId,
  3051.         22, kSLex_Struct,        2,    kSPrs_Expr,    kSLex_ParsedId,
  3052.         23, kSLex_Value,        2,    kSPrs_Expr,    kSLex_ParsedId,
  3053.         24, kSLex_Ellipsis,        2,    kSPrs_Expr,    kSLex_ParsedId,
  3054.          0,    kSLex_LParen,        1,    kSPrs_Expr,
  3055.          1,    kSLex_LBrace,        1,    kSPrs_Expr,
  3056.          2, kSLex_Struct,        1,    kSPrs_Expr,
  3057.         35, kSLex_Decl,            1,    kSPrs_Expr,
  3058.          3, kSLex_Op,            1,    kSPrs_Expr,
  3059. //        32, kSLex_OpQuestion,    1,    kSPrs_Expr,
  3060.          4, kSLex_ParsedId,        1,    kSPrs_Expr,
  3061.          5, kSPrs_DeclType,        1,    kSPrs_Expr,
  3062.          6, kSLex_Value,        1,    kSPrs_Expr,
  3063.          7, kSLex_Ellipsis,        1,    kSPrs_Expr,
  3064.         34, kSLex_LParen,        0,
  3065.         18, -1,                    2,    kSPrs_Expr,    kSLex_Op,
  3066.         25, -1,                    2,    kSPrs_Expr,    kSLex_ParsedId,
  3067.         33, -1,                    2,    kSPrs_Expr,    kSPrs_Decl,
  3068.  
  3069.         -1, -1,                    0
  3070.         //ƒ+
  3071.         };
  3072.         
  3073.     /*
  3074.     ** Hack.  Various states are hidden under other states.
  3075.     **
  3076.     **        (3)            ->    (32)
  3077.     **            The operator might a "?", part of a destructor name.
  3078.     */
  3079.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  3080.     switch (anIndex)
  3081.         {
  3082.     case  3:
  3083.         if (aToken->MinorType() == kSLex_OpQuestion)
  3084.             anIndex = 32;
  3085.         break;
  3086.         }
  3087.  
  3088.     DEBUGPARSER(Expr, anIndex);
  3089.  
  3090.     switch (anIndex)
  3091.         {
  3092.     case  0:    //    ® • "("                                    -> ® kSLex_Context "(" kSPrs_Expr •
  3093.     case  1:    //    ® • "["                                    -> ® kSLex_Context "[" kSPrs_Expr •
  3094.         aFormat->OpenContext();
  3095.         DEBUGSETCONTEXT(setExprContext)
  3096.         setExprContext(aFormat);
  3097.         aFormat->LParen();
  3098.         aFormat->Display(aToken);
  3099.         aParser->Shift(&gContext);
  3100.         aParser->Shift(aToken);
  3101.         aParser->Shift(&gPrsExpr);
  3102.         break;
  3103.  
  3104.     case 34:    //    ? • "("                                -> ? kSPrs_Expr • "("
  3105.         aParser->Shift(&gPrsExpr);
  3106.         aParser->Parse(aToken);
  3107.         break;
  3108.  
  3109.     case  2:    //    ® • "struct"                        -> ® kSPrs_Decl • "struct"
  3110.     case 35:    //    ® • kSLex_Decl                        -> ® kSPrs_Decl • kSLex_Decl
  3111.         DEBUGSETCONTEXT(setDeclContext)
  3112.         setDeclContext(aFormat);
  3113.         aFormat->SetGlue((FormatString)"&n");            // Don't newline
  3114.         aParser->Shift(&gPrsDecl);
  3115.         aParser->Parse(aToken);
  3116.         break;
  3117.  
  3118.     case 33:    //    ® kSPrs_Decl • ???                    -> ® • ???
  3119.         if (aToken->IsSeparator())
  3120.             {
  3121.             aFormat->Display(aToken);
  3122.             return (true);
  3123.             }
  3124.         aParser->Drop(1);
  3125.         return (Accept(aToken, aParser));
  3126.  
  3127.     case  3:    //    ® • kSLex_Op                        -> ® kSLex_Op •
  3128.         //aFormat->Operator();
  3129.         aFormat->Display(aToken);
  3130.         aParser->Shift(aToken);
  3131.         break;
  3132.  
  3133.     case  4:    //    ® • kSLex_ParsedId                    -> ® kSLex_ParsedId •
  3134.     case  5:    //    ® • kSPrs_DeclType                    -> ® kSLex_ParsedId •
  3135.     case  6:    //    ® • kSLex_Value                        -> ® kSLex_ParsedId •
  3136.     case  7:    //    ® • kSLex_Ellipsis                    -> ® kSLex_ParsedId •
  3137.         aFormat->Name();
  3138.         aFormat->Display(aToken);
  3139.         aParser->Shift(&gLexParsedId);
  3140.         break;
  3141.  
  3142.     case  8:    //    ® kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_ParsedId •
  3143.     case 10:    //    ® kSLex_Context "[" kSPrs_Expr • "]"    -> ® kSLex_ParsedId •
  3144.         aFormat->RParen();
  3145.         aFormat->Display(aToken);
  3146.         aFormat->CloseContext();
  3147.         aParser->Drop(3);
  3148.         aParser->Shift(&gLexParsedId);
  3149.         break;
  3150.  
  3151.     case  9:    //    ® kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_Context "(" kSPrs_Expr •
  3152.     case 11:    //    ® kSLex_Context "[" kSPrs_Expr • ","    -> ® kSLex_Context "[" kSPrs_Expr •
  3153.     case 31:    //    ® kSLex_Context "?" kSPrs_Expr • ","    -> ® kSLex_Context "?" kSPrs_Expr •
  3154.         aFormat->Comma();
  3155.         aFormat->Display(aToken);
  3156.         break;
  3157.  
  3158.     case 32:    //    ® • "?"                                    -> ® kSLex_Context "?" kSPrs_Expr •
  3159.         aFormat->OpenContext();
  3160.         DEBUGSETCONTEXT(setExprContext)
  3161.         setExprContext(aFormat);
  3162.         aFormat->SetGlue(gFS_expr2);
  3163.         aFormat->Display(aToken);
  3164.         aParser->Shift(&gContext);
  3165.         aParser->Shift(&gLexQuestion);
  3166.         aParser->Shift(&gPrsExpr);
  3167.         break;
  3168.  
  3169.     case 28:    //    ® kSLex_Context "?" kSPrs_Expr • ":"    -> ® •
  3170.         aFormat->SetGlue(gFS_expr3);
  3171.         aFormat->Display(aToken);
  3172.         aFormat->CloseContext();
  3173.         aParser->Drop(3);
  3174.         break;
  3175.  
  3176.     case 12:    //    ® kSLex_Op • "("            -> ® • "("
  3177.     case 26:    //    ® kSLex_Op • "["            -> ® • "["
  3178.         aParser->Drop(1);
  3179.         return (Accept(aToken, aParser));
  3180.  
  3181.     case 15:    //    ® kSLex_Op • kSLex_Struct        -> ® kSPrs_Struct • "struct"
  3182.     case 22:    //    ® kSLex_ParsedId • kSLex_Struct    -> ® kSPrs_Struct • "struct"
  3183.         aFormat->Name();
  3184.         aFormat->SetGlue((FormatString)"&n");            // Don't newline
  3185.         DEBUGSETCONTEXT(setDeclContext)
  3186.         setDeclContext(aFormat);
  3187.         aParser->TopItem(&gPrsDecl);
  3188.         aParser->Parse(aToken);
  3189.         break;
  3190.  
  3191.     case 14:    //    ® kSLex_Op • kSLex_ParsedId        -> ® kSLex_ParsedId •
  3192.     case 16:    //    ® kSLex_Op • kSLex_Value        -> ® kSLex_ParsedId •
  3193.     case 17:    //    ® kSLex_Op • kSLex_Ellipsis        -> ® kSLex_ParsedId •
  3194.         aFormat->Name();
  3195.         aFormat->Display(aToken);
  3196.         aParser->TopItem(&gLexParsedId);
  3197.         break;
  3198.  
  3199.     case 18:    //    ® kSLex_Op • ???                -> ® • ???
  3200.         if (aToken->IsSeparator())
  3201.             {
  3202.             aFormat->Display(aToken);
  3203.             return (true);
  3204.             }
  3205.         aParser->Drop(1);
  3206.         return (Accept(aToken, aParser));
  3207.  
  3208.     case 25:    //    ® kSLex_ParsedId • ???                -> ® • ???
  3209.         if (aToken->IsSeparator())
  3210.             {
  3211.             aFormat->Display(aToken);
  3212.             return (true);
  3213.             }
  3214.         aParser->Drop(1);
  3215.         return (Accept(aToken, aParser));
  3216.  
  3217.     case 19:    //    ® kSLex_ParsedId • "("                                -> ® kSLex_ParsedId kSLex_Context "(" kSPrs_Expr •
  3218.         aFormat->OpenContext();
  3219.         DEBUGSETCONTEXT(setFuncallContext)
  3220.         setFuncallContext(aFormat);
  3221.         aFormat->LParen();
  3222.         aFormat->Display(aToken);
  3223.         aParser->Shift(&gContext);
  3224.         aParser->Shift(aToken);
  3225.         aParser->Shift(&gPrsExpr);
  3226.         break;
  3227.  
  3228.     case 29:    //    ® kSLex_ParsedId kSLex_Context "(" kSPrs_Expr • ","    -> ® kSLex_ParsedId kSLex_Context "(" kSPrs_Expr •
  3229.         aFormat->Comma();
  3230.         aFormat->Display(aToken);
  3231.         break;
  3232.  
  3233.     case 36:    //    ® kSLex_ParsedId kSLex_Context "(" kSPrs_Expr • ")"    -> ® kSLex_ParsedId •
  3234.         aFormat->RParen();
  3235.         aFormat->Display(aToken);
  3236.         aFormat->CloseContext();
  3237.         aParser->Drop(3);
  3238.         break;
  3239.  
  3240.  
  3241.     case 13:    //    ® kSLex_Op • kSLex_Op                -> ® kSLex_Op •
  3242.     case 20:    //    ® kSLex_ParsedId • kSLex_Op            -> ® kSLex_Op •
  3243.         // This is not a prefix operator.  Consequently we apply the 
  3244.         // operator glue.  However, some operators are always adjoined
  3245.         // to their left hand side: postfix incrementors and member
  3246.         // qualifiers.  Don't use operator glue for these.
  3247.         switch (aToken->MinorType())
  3248.             {
  3249.         case kSLex_OpClassStar:
  3250.         case kSLex_OpDotStar:
  3251.         case kSLex_OpPointerStar:
  3252.         case kSLex_OpDot:
  3253.         case kSLex_OpPointer:
  3254.             // The only glue for these is none.  No spaces between this
  3255.             // operator and what was on the left of it.
  3256.             aFormat->SetGlue((FormatString)"!s");
  3257.             break;
  3258.  
  3259.         case kSLex_OpPlusPlus:
  3260.         case kSLex_OpMinusMinus:
  3261.             {
  3262.             Syntactic* topItem = aParser->TopItem();
  3263.  
  3264.             // Make sure that these operators are not transformed into
  3265.             // something wrong: "- --x" should not become "---x".  We are
  3266.             // cheesy here: "-++x" becomes "- ++x" even though it doesn't
  3267.             // have to.
  3268.             if (topItem->MinorType() == kSLex_OpAdd || topItem->MinorType() == kSLex_OpSub)
  3269.                 aFormat->SetGlue((FormatString)"?n{}{&s}•");
  3270.             else
  3271.                 aFormat->SetGlue((FormatString)"!s");
  3272.             }
  3273.             break;
  3274.  
  3275.         case kSLex_OpAssign:
  3276.         case kSLex_OpAssignMul:
  3277.         case kSLex_OpAssignDiv:
  3278.         case kSLex_OpAssignMod:
  3279.         case kSLex_OpAssignAdd:
  3280.         case kSLex_OpAssignSub:
  3281.         case kSLex_OpAssignRSh:
  3282.         case kSLex_OpAssignLSh:
  3283.         case kSLex_OpAssignBAnd:
  3284.         case kSLex_OpAssignBXor:
  3285.         case kSLex_OpAssignBOr:
  3286.             // This is an assignment operator.  Apply the assignment operator
  3287.             // glue to the format.
  3288.             aFormat->Assign();
  3289.             break;
  3290.             
  3291.         case kSLex_OpQuestion:
  3292.             // Handle the question operator
  3293.             aParser->Drop(1);
  3294.             return (Accept(aToken, aParser));
  3295.  
  3296.         default:
  3297.             {
  3298.             Syntactic* topItem = aParser->TopItem();
  3299.  
  3300.             // If the previous item was an operator and not ++ or --, then this
  3301.             // is a unary operator.  Emit glue for it as such.
  3302.             if (topItem->Type() == kSLex_Op                    &&
  3303.                 topItem->MinorType() != kSLex_OpPlusPlus    &&
  3304.                 topItem->MinorType() != kSLex_OpMinusMinus)
  3305.                 {
  3306.                 Boolean isSpecialUnary = false;
  3307.  
  3308.                 // Compare the previous operator with this current operator.
  3309.                 // It behooves us to emit a blank to avoid changing "- -x"
  3310.                 // into "--x", a totally different statement.  If this is the case,
  3311.                 // require a blank by emitting glue to that effect.
  3312.                 switch (aToken->MinorType())
  3313.                     {
  3314.                 case kSLex_OpAdd:
  3315.                 case kSLex_OpSub:
  3316.                     isSpecialUnary = (topItem->MinorType() == aToken->MinorType());
  3317.                     break;
  3318.                     }
  3319.  
  3320.                 if (isSpecialUnary)
  3321.                     aFormat->SetGlue((FormatString)"?n{}{&s}•");
  3322.                 else
  3323.                     aFormat->SetGlue((FormatString)"•!s");
  3324.                 }
  3325.             else
  3326.                 aFormat->Operator();
  3327.             break;
  3328.             }
  3329.             }
  3330.         aFormat->Display(aToken);
  3331.         aParser->TopItem(aToken);
  3332.         break;
  3333.  
  3334.     case 27:    //    ® kSLex_ParsedId • "["                -> ® • "["
  3335.         aParser->Drop(1);
  3336.         return (Accept(aToken, aParser));
  3337.  
  3338.     case 21:    //    ® kSLex_ParsedId • kSLex_ParsedId    -> ® kSLex_ParsedId •
  3339.     case 23:    //    ® kSLex_ParsedId • kSLex_Value        -> ® kSLex_ParsedId •
  3340.     case 24:    //    ® kSLex_ParsedId • kSLex_Ellipsis    -> ® kSLex_ParsedId •
  3341.         aFormat->Name();
  3342.         aFormat->Display(aToken);
  3343.         break;
  3344.  
  3345.     default:
  3346.         if (aToken->IsSeparator())
  3347.             {
  3348.             aFormat->Display(aToken);
  3349.             return (true);
  3350.             }
  3351.         return (false);
  3352.         }
  3353.         
  3354.     return (true);
  3355.     }
  3356.  
  3357.  
  3358.  
  3359. /*µ kSPrs_DeclOperator    ( 9)
  3360. **    ( 0)    ? ® • "operator"                    -> "operator" ® •
  3361. **    ( 1)    ? "operator" ® • kSLex_Id            -> • kSLex_Id
  3362. **    ( 2)    ? "operator" ® • kSLex_Op            -> • kSLex_Id
  3363. **    ( 3)    ? "operator" ® • "("                -> ? "operator" "(" ® •
  3364. **    ( 4)    ? "operator" ® • "["                -> ? "operator" "[" ® •
  3365. **    ( 5)    ? "operator" "(" ® • ")"            -> • kSLex_Id
  3366. **    ( 6)    ? "operator" "[" ® • "]"            -> • kSLex_Id
  3367. **    ( 7)    ? "operator" "(" ® • ???            -> ? • kSLex_ParsedId "(" ???
  3368. **    ( 8)    ? "operator" "[" ® • ???            -> ? • kSLex_ParsedId "[" ???
  3369. **    ( 9)    ? "operator" ® • ???                -> ? • kSLex_ParsedId ???
  3370. **    Parse the phrase "operator".  When done, it has changed its sex into
  3371. ** kSLex_Id and can be used anywhere that a kSLex_Id can be used.  The
  3372. ** states where an error might be possible will be assumed to result in the
  3373. ** identifier "operator" being parsed and the tokens following to be sent
  3374. ** along.
  3375. */
  3376. #pragma segment ParserActions
  3377. Boolean
  3378. PrsDeclOperator::Accept(Syntactic *aToken, Parser *aParser)
  3379. {
  3380.     Formatting * aFormat = aParser->GetFormatting();
  3381.     static const short handles[] = {
  3382.                                     //ƒ-
  3383.          5, kSLex_RParen,        3,    kSLex_DeclOperator,    kSLex_LParen,        kSPrs_DeclOperator,
  3384.          6, kSLex_RBrace,        3,    kSLex_DeclOperator,    kSLex_LBrace,        kSPrs_DeclOperator,
  3385.          1,    kSLex_Id,            2,    kSLex_DeclOperator,    kSPrs_DeclOperator,
  3386.          2,    kSLex_Op,            2,    kSLex_DeclOperator,    kSPrs_DeclOperator,
  3387.          3,    kSLex_LParen,        2,    kSLex_DeclOperator,    kSPrs_DeclOperator,
  3388.          4,    kSLex_LBrace,        2,    kSLex_DeclOperator,    kSPrs_DeclOperator,
  3389.          0,    kSLex_DeclOperator,    1,    kSPrs_DeclOperator,
  3390.          7, -1,                    3,    kSLex_DeclOperator,    kSLex_LParen,        kSPrs_DeclOperator,
  3391.          8, -1,                    3,    kSLex_DeclOperator,    kSLex_LBrace,        kSPrs_DeclOperator,
  3392.          9,    -1,                    2,    kSLex_DeclOperator,    kSPrs_DeclOperator,
  3393.  
  3394.         -1, -1,                    0
  3395.         //ƒ+
  3396.                                     };
  3397.  
  3398.     short anIndex = aParser->FindHandle(aToken->Type(), handles);
  3399.  
  3400.     switch (anIndex)
  3401.         {
  3402.     case  0:    //    ? ® • "operator"                    -> "operator" ® •
  3403.         aParser->TopItem(aToken);
  3404.         aParser->Shift(this);
  3405.         break;
  3406.  
  3407.     case  1:    //    ? "operator" ® • kSLex_Id            -> • kSLex_Id
  3408.     case  2:    //    ? "operator" ® • kSLex_Op            -> • kSLex_Id
  3409.         fToken = aToken;
  3410.         SexChange(kSLex_Id);
  3411.         aParser->Reduce(this, 2);
  3412.         break;
  3413.  
  3414.     case  3:    //    ? "operator" ® • "("                -> ? "operator" "(" ® •
  3415.     case  4:    //    ? "operator" ® • "["                -> ? "operator" "[" ® •
  3416.         fToken = aToken;
  3417.         aParser->TopItem(aToken);
  3418.         aParser->Shift(this);
  3419.         break;
  3420.  
  3421.     case  5:    //    ? "operator" "(" ® • ")"            -> • kSLex_Id
  3422.     case  6:    //    ? "operator" "[" ® • "]"            -> • kSLex_Id
  3423.         SexChange(kSLex_Id);
  3424.         aParser->Reduce(this, 3);
  3425.         break;
  3426.  
  3427.     case  7:    //    ? "operator" "(" ® • ???            -> ? • kSLex_ParsedId "(" ???
  3428.     case  8:    //    ? "operator" "[" ® • ???            -> ? • kSLex_ParsedId "[" ???
  3429.         {
  3430.         Syntactic* open = aParser->Pick(1);
  3431.         
  3432.         if (aToken->IsSeparator())
  3433.             {
  3434.             aFormat->Display(aToken);
  3435.             return (true);
  3436.             }
  3437.         aParser->Drop(3);
  3438.         return (aParser->Parse(&gLexOperator) && aParser->Parse(open) && aParser->Parse(aToken));
  3439.         }
  3440.  
  3441.     case  9:    //    ? "operator" ® • ???                -> ? • kSLex_ParsedId ???
  3442.         if (aToken->IsSeparator())
  3443.             {
  3444.             aFormat->Display(aToken);
  3445.             return (true);
  3446.             }
  3447.         aParser->Drop(2);
  3448.         return (aParser->Parse(&gLexOperator) && aParser->Parse(aToken));
  3449.  
  3450.     default:
  3451.         if (aToken->IsSeparator())
  3452.             {
  3453.             aFormat->Display(aToken);
  3454.             return (true);
  3455.             }
  3456.         return (false);
  3457.         }
  3458.         
  3459.     return (true);
  3460.     }
  3461.  
  3462.  
  3463.  
  3464. /*µ kSPrs_NewLine
  3465. **    If the newline is followed by an opening curly or the keyword "else", then
  3466. ** this newline can be ignored.  Other tokens require that the newline be passed
  3467. ** along and then the new token be handled.
  3468. */
  3469. //µ PrsNewLine::Accept
  3470. #pragma segment ParserActions
  3471. Boolean PrsNewLine::Accept(Syntactic *aToken, Parser *aParser)
  3472. {
  3473.     aParser->Drop(1);
  3474.  
  3475.     switch (aToken->Type()) {
  3476.     case kSLex_LCurly:
  3477.     case kSLex_Else:
  3478.         return (aParser->Parse(aToken));
  3479.  
  3480.     default:
  3481.         aParser->Parse(this);
  3482.         return (aParser->Parse(aToken));
  3483.     }
  3484.  
  3485.     return (true);
  3486. }
  3487.  
  3488.  
  3489.  
  3490. //µ PrsNewLineIf::Accept
  3491. Boolean PrsNewLineIf::Accept(Syntactic *aToken, Parser *aParser)
  3492. {
  3493.     switch (aToken->Type()) {
  3494.     case kSLex_If:
  3495.         aParser->Drop(1);
  3496.         return (aParser->Parse(aToken));
  3497.  
  3498.     default:
  3499.         return (PrsNewLine::Accept(aToken, aParser));
  3500.     }
  3501.  
  3502.     return (true);
  3503. }
  3504.  
  3505.  
  3506.  
  3507. /*
  3508. ** Display methods
  3509. */
  3510. //µ SyntacticPrs::Display
  3511. #pragma segment ParserActions
  3512. Boolean SyntacticPrs::Display(Formatting *)
  3513. {
  3514.     // Doesn't display
  3515.     return (false);
  3516. }
  3517.  
  3518.  
  3519. //µ PrsPlaceHolder::Display
  3520. #pragma segment ParserActions
  3521. Boolean PrsPlaceHolder::Display(Formatting *aFormat)
  3522. {
  3523.     // Display the string.  Return true if there was a string to display
  3524.     aFormat->Print(fString);
  3525.     return (fString && *fString);
  3526. }
  3527.  
  3528.  
  3529. //µ PrsId::Display
  3530. #pragma segment ParserActions
  3531. Boolean PrsId::Display(Formatting *aFormat)
  3532. {
  3533.     aFormat->Display(fClassName);
  3534.     aFormat->Display(fClassOp);
  3535.     aFormat->Display(fMemberName);
  3536.  
  3537.     // Return false.  The above aFormat->Display() call is what was important,
  3538.     // not this placeholder
  3539.     return (false);
  3540. }
  3541.  
  3542.  
  3543. //µ PrsDestructor::Display
  3544. #pragma segment ParserActions
  3545. Boolean PrsDestructor::Display(Formatting *aFormat)
  3546. {
  3547.     aFormat->Display(&gLexBNot);
  3548.     aFormat->Display(fMemberName);
  3549.  
  3550.     // Return false.  The above aFormat->Display() call is what was important,
  3551.     // not this placeholder
  3552.     return (false);
  3553. }
  3554.  
  3555.  
  3556. //µ PrsAsId::Display
  3557. #pragma segment ParserActions
  3558. Boolean PrsAsId::Display(Formatting *aFormat)
  3559. {
  3560.     // Hand it off to the token itself
  3561.     aFormat->Display(fToken);
  3562.  
  3563.     // Return false.  The above aFormat->Display() call is what was important,
  3564.     // not this placeholder
  3565.     return (false);
  3566. }
  3567.  
  3568.  
  3569. /*
  3570. ** Display the contents of the "operator"
  3571. */
  3572. //µ PrsDeclOperator::Display
  3573. #pragma segment ParserActions
  3574. Boolean PrsDeclOperator::Display(Formatting *aFormat)
  3575. {
  3576.     short aType = fToken->Type();
  3577.  
  3578.     aFormat->Display(&gLexOperator);
  3579.  
  3580.     switch (aType) {
  3581.     case kSLex_Id:
  3582.     case kSLex_ParsedId:
  3583.         aFormat->Name();
  3584.         break;
  3585.     }
  3586.  
  3587.     aFormat->Display(fToken);
  3588.  
  3589.     switch (aType) {
  3590.     case kSLex_LParen:
  3591.         aFormat->Display(&gLexRParen);
  3592.         break;
  3593.  
  3594.     case kSLex_LBrace:
  3595.         aFormat->Display(&gLexRBrace);
  3596.         break;
  3597.     }
  3598.  
  3599.     // Return false, as this PrsDeclOperator token should not affect the
  3600.     // display: what was last passed to aFormat->Display() should affect
  3601.     // the display.
  3602.     return (false);
  3603. }
  3604.  
  3605.  
  3606.  
  3607. //µ PrsNewLine::IsSeparator
  3608. #pragma segment ParserActions
  3609. Boolean PrsNewLine::IsSeparator() const
  3610. {
  3611.     return (true);
  3612. }
  3613.  
  3614.  
  3615.  
  3616. //µ PrsNewLine::Display
  3617. #pragma segment ParserActions
  3618. Boolean PrsNewLine::Display(Formatting *aFormat)
  3619. {
  3620.     aFormat->NewLine();
  3621.     return (true);
  3622. }
  3623.  
  3624.  
  3625.  
  3626. //µ SyntacticPrs::IsSeparator
  3627. #pragma segment ParserActions
  3628. Boolean SyntacticPrs::IsSeparator() const
  3629. {
  3630.     return (false);
  3631. }
  3632.  
  3633.  
  3634.  
  3635. //µ SyntacticPrs::SaveCopy
  3636. #pragma segment ParserActions
  3637. const Syntactic *SyntacticPrs::SaveCopy() const
  3638. {
  3639.     return (this);
  3640. }
  3641.  
  3642.  
  3643. //µ PrsPlaceHolder::Accept
  3644. #pragma segment ParserActions
  3645. Boolean PrsPlaceHolder::Accept(Syntactic *, Parser *)
  3646. {
  3647.     return (false);
  3648. }
  3649.  
  3650.  
  3651.